Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Six people stand in a circle numbered 1 to 6. Starting from person 1, every 4th person (counting the start as 1) is removed until one remains. Which person survives?

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

Correct answer: C. 5

Use a circular queue: rotate three times, then remove the front. Off-by-one in the rotation count is the common mistake.

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

Exams that ask this topic