Data Structures & AlgorithmsVery hardICPC regional · TCS NQT Digital

Problem: 23 people stand in a circle numbered 1 to 23. Starting at person 1, every second person is eliminated (counting around the circle, so person 2 goes first, then 4, and so on), until one remains. Which person survives?

  1. A. 15
  2. B. 14
  3. C. 13
  4. D. 7

Correct answer: A. 15

For k = 2 write n = 2^m + L: 23 = 16 + 7, so the survivor is 2L + 1 = 15. Dropping the + 1 gives 14, using n = 22 gives 13, and reporting L itself gives 7.

More Coding Interview Problems questions

Exams that ask this topic