Find conflicting pair using black-box run()
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates algorithm design and query-complexity reasoning, focusing on efficient search strategies for identifying an interacting pair via a costly black-box oracle.
Constraints
- 2 <= len(tests) <= 10^5
- `tests` contains distinct integers
- `conflict_pair` contains exactly two values from `tests`
- `run(subset)` returns `FAIL` iff both hidden conflicting IDs are in `subset`
- An O(n^2) search over all pairs is not acceptable
Examples
Input: ([1, 2, 3, 4, 5, 6], (5, 2))
Expected Output: [2, 5]
Explanation: Only subsets containing both 2 and 5 fail. The returned order follows their order in `tests`.
Input: ([10, 20], (20, 10))
Expected Output: [10, 20]
Explanation: This is the smallest valid input. With only two tests, they must be the conflicting pair.
Input: ([-3, -1, 0, 7, 9], (-3, 9))
Expected Output: [-3, 9]
Explanation: Negative values are valid IDs. The conflict occurs only when both -3 and 9 are included.
Input: ([4, 8, 15, 16, 23, 42, 50, 60], (42, 23))
Expected Output: [23, 42]
Explanation: Both conflicting tests lie in the same half at first, so repeated halving isolates them quickly.
Hints
- Split the current candidate set into two halves. If one half fails by itself, then both conflicting tests are inside that half.
- If both halves pass, then the conflicting pair is split across the halves. Use one half as an anchor and binary search the other half.