Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2

The same rule, with every 3rd person eliminated, applies to n = 41 people. Who survives (1-based)?

  1. A. 16
  2. B. 28
  3. C. 31
  4. D. 40

Correct answer: C. 31

The Josephus recurrence J(n) = (J(n−1) + 3) mod n with J(1) = 0 gives 30 in 0-based terms, that is person 31. Simulating the queue gives the same answer.

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

Exams that ask this topic