The Josephus Survivor — Solution & Editorial
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)
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)