Josephus problem
Your task
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).
Examples
josephus(n: int, k: int) -> intExample 1
Input
josephus(5, 2)Output
3