GATE Computer ScienceHardGATE CS (PYQ pattern)

Ten people numbered 1 to 10 stand in a circle (a circular linked list in increasing order). Counting starts at person s, who is counted as 1; every 3rd person still present is removed, and counting resumes at the next person, until one person remains. With s = 1 the survivor is person 4. For which starting person s does person 1 survive?

  1. A. 9
  2. B. 7
  3. C. 4
  4. D. 8

Correct answer: D. 8

Starting the count one place later rotates the whole elimination pattern one place forward, so the survivor for start s is ((4 - 1) + (s - 1)) mod 10 + 1. Setting this equal to 1 needs (s + 2) mod 10 = 0, i.e. s = 8; a direct simulation from s = 8 confirms that person 1 is left.

More Programming and Data Structures (GATE) questions

Exams that ask this topic