Loading...
Loading...
Loading...
n people numbered 1 to n stand in a circle. Starting from person 1, count k people. The k-th person leaves the circle, and counting restarts from the next person. This repeats until one person is left. Print that person's number.
Example 1
Input
5 2
Output
3
The order of leaving is 2, 4, 1, 5. Person 3 stays.
Example 2
Input
7 3
Output
4
Try the problem first. Open one hint at a time.
Put the people in a deque and rotate left by k - 1 so the leaving person is at the front.
Then popleft removes them.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor