Find faulty commit using deployment function
Filed under Amazon
Free read 1 of 3Identify the search range for both A and B.
The question
You have a function deploy(a, b) that returns true if commits 1..a of project A and 1..b of project B are stable. Given the system is currently failing, find the first commit pair (a, b) that caused the failure using binary search.
Constraints
- Function is monotonic (true followed by false)
- Search space is defined by the range of commits
- Minimize calls to deploy(a, b)
Approach
Identify the search range for both A and B.
Perform binary search on project A. For each mid_a, perform a binary search on project B to find the transition point.
If the relationship between A and B is fixed, reduce to a single binary search.
Handle cases where the first commit is already failing.
Tips
- What they are testing: Consider if the search space is 1D or 2D; if 2D, nested binary search is required.
- Common mistake: Off-by-one errors in binary search range boundaries.
Related Amazon questions
Collected from public candidate posts and coding forums. Updated Nov 2026.