Data Structures & AlgorithmsHardGATE CS

50 people stand in a circle numbered 1 to 50. Starting the count at person 1, every 7th person (counting the first as 1) is removed, and counting resumes with the next person. Which numbered person is the last survivor?

  1. A. 8
  2. B. 41
  3. C. 1
  4. D. 45

Correct answer: C. 1

Use J(1)=0 and J(i)=(J(i-1)+7) mod i, then add 1: the survivor is person 1. Changing k by one moves the survivor to person 45 or 41.

More Coding Interview Problems questions

Exams that ask this topic