Data Structures & AlgorithmsHardGATE CS · DSA

9 people stand in a circle numbered 1 to 9. Counting starts at person 1, and every 3rd person is removed (counting continues from the next person). Simulating with a queue, who survives, and who is removed third?

  1. A. Survivor 1; third removed 6
  2. B. Survivor 7; third removed 9
  3. C. Survivor 1; third removed 9
  4. D. Survivor 2; third removed 9

Correct answer: C. Survivor 1; third removed 9

Rotate the queue k − 1 times and dequeue the next person each round. Removal order: 3, 6, 9, 4, 8, 5, 2, 7, leaving 1.

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

Exams that ask this topic