Problems > The Josephus Survivor > Editorial

The Josephus Survivor — Solution & Editorial

Back to the Problem

Use the classic recurrence J(1) = 0, J(m) = (J(m−1) + K) mod m, answering J(N) + 1. Direct list simulation is O(NK) and too slow for large K.

Complexity: O(N)