n friends numbered 1 to n sit in a clockwise circle. Starting at friend 1, count k friends clockwise (including the starting friend); the last one counted leaves the circle. Counting then restarts at the friend just clockwise of the one who left. The last friend remaining wins. Return the winner.
n friends numbered 1 to n sit in a clockwise circle. Starting at friend 1, count k friends clockwise (including the starting friend); the last one counted leaves the circle. Counting then restarts at the friend just clockwise of the one who left. The last friend remaining wins. Return the winner.
Example 1:
Input: {"n":5,"k":2}
Output: 3
Constraints:
1≤k≤n≤500
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":5,"k":2}
5 friends sit in a circle. Counting 2 clockwise from friend 1, the last one counted leaves.
the game, n = 5, k = 2
12345k = 2
blue ring = counting starts here · amber = counted · red = leaves