Catching the spy on a number line
A spy is somewhere on the integer number line. At time 0 the spy is at integer A; at each time step the spy moves B units to the right (B may be negative or zero), so at time t the spy is at A + Bt. Both A and B are fixed integers unknown to you.
At each time t = 0, 1, 2, ..., you may name one location and ask "is the spy there now?" and you are told yes or no.
Devise a strategy that is guaranteed to find the spy eventually, whatever A and B are.
Show a hint
There are only countably many possibilities for the pair (A, B). List them all in a sequence, and at time t check where the spy would be if the t-th pair were the truth.
Your answer
Solving needs a free account
Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.
Discussion
💡 Discussion rules
- No full solutions here. Hints and approaches only.
- Complexity, edge cases and intuition are the point.
- Interview experiences are welcome. Respect your NDAs.
Loading discussion…
Learn the concepts
The theory behind this question.