Find bad GPU nodes with group tests

0
Sign in

A cluster has n GPU nodes with ids 0 to n - 1. Each node is either good or bad, and you do not know which in advance. The only way to learn anything is a test service:

class TestServer:
    def test(self, nodes: list[int]) -> bool:
        # True if every node in `nodes` is good; False if at least one is bad.
        ...

A failing test does not say which node is bad or how many are bad. Each call runs a real health job on the hardware, so calls are expensive.

Implement find_bad_nodes(n: int, server: TestServer) -> list[int]. It returns the ids of all bad nodes in ascending order and uses as few test calls as you can.

Constraints

  • 0 <= n <= 10^5
  • Any number of nodes may be bad, including none or all of them. In practice bad nodes are rare.
  • Testing every node on its own (n calls) is correct but too slow when n is large. Aim for a call count that depends mainly on the number of bad nodes k.

Example 1

n = 8, bad nodes = {2, 5}
output: [2, 5]

Testing [0..7] fails, so split. [0..3] fails and [4..7] fails, so keep splitting each half until single nodes remain. Halves that pass, such as [0, 1] and [6, 7], are cleared with one call each.

Example 2

n = 6, bad nodes = {}
output: []

One call on [0..5] passes, so every node is good.

Be ready for follow-ups: there is exactly one bad node, tests run in parallel rounds, you know an upper bound on the number of bad nodes, or tests are sometimes wrong.

xAITechnical phone screenMediumLast asked Dec 2025

Sign in to see the worked answer

The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.