Data Structures & AlgorithmsHardCodeforces Div2 B · recurrence problems

Problem: n = 10 people stand in a circle and every 3rd person is removed until one remains (counting starts at person 1 and the removed person's neighbour is next). Using the recurrence J(1) = 0, J(i) = (J(i-1) + 3) mod i and answering 1-indexed, which person survives?

  1. A. 2
  2. B. 7
  3. C. 10
  4. D. 4

Correct answer: D. 4

The recurrence gives J(10) = 3 (0-indexed), so the survivor is person 4 in 1-indexed numbering. Reporting the 0-indexed value 3 is a common off-by-one trap.

More Coding Interview Problems questions

Exams that ask this topic