Qm
BrainteasersJane StreetSIG

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

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. No full solutions here. Hints and approaches only.
  2. Complexity, edge cases and intuition are the point.
  3. Interview experiences are welcome. Respect your NDAs.

Loading discussion…

Learn the concepts

The theory behind this question.

Related questions

Ten prisoners and hats of ten colorsThe warden knows the chain strategyOne helper who may swap two slips100 prisoners guessing hat colors in a line100 prisoners and 100 boxes
All questions →