← Questions

Find the conflicting pair of tests with a black-box runner

0
GoogleCodingLast asked Jan 2026

A coding interview question asked in Google's onsite coding round, last asked Jan 2026. It tests binary-search, divide and conquer and debugging.

You have n tests, numbered 1..n. Each test passes when run alone, but exactly one pair of tests conflicts: any run that includes both of them fails. You can only learn about the tests through a black box, run(tests), which runs a set of tests together and reports whether the run passed. Each call is expensive. Find the conflicting pair with as few calls as possible.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • run(tests: set[int]) -> bool — provided; True when the set passes, False when it contains both tests of the conflicting pair.
  • find_conflict(n: int, run) -> tuple[int, int] — returns the pair (i, j) with i < j.

Example

n = 8, the hidden pair is (3, 6)

binary search on prefixes {1..m}: the smallest failing prefix is {1..6}, so j = 6
binary search on {m..5} plus {6}: the largest m that still fails is 3, so i = 3
find_conflict(8, run)  ->  (3, 6)      # 5 calls in total, versus up to 28 pair tests

Constraints

  • 2 <= n <= 10^5.
  • Aim for O(log n) calls; the time spent outside run is not the bottleneck.

Clarifying questions

  • Exactly one conflicting pair, or possibly several?
  • Does the order of tests within a run matter?
  • Is run deterministic, or can tests be flaky?
  • Is there a limit on how many tests one run may contain?

What a strong answer covers

  • Brute force over pairs is O(n^2) calls.
  • The prefix idea: a prefix {1..m} fails exactly when it contains both tests, so the smallest failing prefix ends at the larger test j. Binary search: about log2 n calls.
  • The second search: with j fixed, the set {m..j-1} ∪ {j} fails exactly when m <= i; binary search again for i. Total about 2 log2 n calls.
  • An information-theory lower bound: there are n(n-1)/2 possible pairs, so at least about 2 log2 n - 1 calls are needed.
  • Tests with the pair at the ends ((1, 2), (n-1, n)).

Follow-ups

  • There may be several conflicting pairs: find all of them, and count calls in terms of n and the number of pairs.
  • A conflict can involve three tests.
  • run is flaky and fails at random 1% of the time.

Where it's asked

  • Google · Onsite coding · Last asked Jan 202645 min · Usually two rounds, mostly in person: whiteboard plus a Chromebook with Google Docs · No AI (a pilot code-comprehension round lets candidates use Gemini)

What it tests

binary-search · divide and conquer · debugging

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding