← 返回 google 的题目列表First Bad Version with Parallel Bucket Search Follow-up
类型:online_judge
Problem: First Bad Version + Parallel Bucket Search Follow-up
You are given product versions 1, 2, ..., n. Starting from some version bad, every version after it is bad, and every version before it is good.
An API is provided:
def isBadVersion(version: int) -> bool:
...
It returns True if version is bad, otherwise False.
Part 1
Implement a function to find the first bad version.
Part 2 Follow-up: Parallel Processing / Bucket Binary Search
Assume you can issue at most p isBadVersion calls in parallel in one round. Design and implement a bucket-based binary search:
In the current candidate interval [lo, hi], split it into at most p consecutive buckets;
Query the right endpoint of each bucket in parallel;
Find the first bucket whose right endpoint is bad;
Narrow the search interval to that bucket and continue until the first bad version is found.
Input Format
For local testing, the input contains one line:
n bad p
where:
n is the total number of versions;
bad is the first bad version, used to simulate isBadVersion;
p is the maximum number of parallel queries per round.
Output Format
Print the first bad version.
Constraints
1 <= bad <= n <= 10^9
1 <= p <= 10^5
Example
Input:
5 4 2
Output:
4
Example
Input
5 4 2
Output
4