Data Structures & AlgorithmsVery hardCodeforces Div2 B · GATE CS

In the Josephus game, 41 people stand in a circle numbered 1 to 41. Starting from person 1, every 3rd person is removed (counting continues around the circle). Which person number survives?

  1. A. 32
  2. B. 30
  3. C. 62
  4. D. 31

Correct answer: D. 31

Simulating with a queue (rotate k-1 times, then remove the front) is O(nk) and is the reliable check; off-by-one in the rotation count shifts the answer by one.

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

Exams that ask this topic