Skip to content

ORIGINAL CODING QUESTION

Fewest load-test trials

A service is stable up to some unknown load level L between 0 and n, and level 0 is always safe. Testing at level x crashes the test server exactly when x > L; a crashed server is lost, while a surviving one can test again. With k identical test servers, return the minimum number of tests that is guaranteed to pin down L in the worst case.

Open practice workspace

Original exercise · hard. Editorial role relevance does not imply a company has asked this question.

Input and output

k n.

Constraints

1 ≤ k ≤ 4; 0 ≤ n ≤ 200.

Example 1

Input

2 6

Output

3

Test level 3 first: a crash leaves levels 1-2 to check one by one, and survival leaves levels 4-6, which two servers settle in two more tests.

Example 2

Input

1 5

Output

5

With one server you must climb level by level: five tests.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

A test at level x either crashes (search below x with one fewer server) or survives (search above x).

Hint 2

tests(k, n) = 1 + min over x of max(tests(k-1, x-1), tests(k, n-x)).

Hint 3

Alternatively ask how many levels t tests with k servers can cover and find the smallest sufficient t.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →