Data Structures & AlgorithmsHardGATE CS · ICPC regional

There are 7 people in a circle numbered 1 to 7. Starting at person 1 and counting 1, 2, 3, ..., every 3rd person is removed until one remains. Which person survives?

  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 8

Correct answer: B. 4

Track the circle as a queue: rotate two times, remove the front; this yields the survivor after six removals.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic