Josephus problem
There are n people standing in a circle numbered 1 to n. Starting the count at person 1, you count k people and eliminate the k-th; counting then resumes from the next survivor. Return the 1-indexed position of the last person remaining. Constraints: 1 <= n <= 1e6, 1 <= k <= 1e6. An O(n) solution is expected (no O(n*k) circular-list simulation).
Implement
josephus(n: int, k: int) → intExamples
in
[5,2]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[5,2]3not run yetsample