Ctrl K

Last One in the Circle

Medium
A group of people children stand in a circle, numbered clockwise from 1 to people; player 1 comes right after player people. They play a counting-out game: 1. Counting starts at player 1. 2. Count step players clockwise, including the one you start on. The count wraps around the circle, so some players may be counted twice. 3. The last player counted leaves the circle. 4. If more than one player remains, the next count starts at the player immediately clockwise of the one who just left, and the process repeats. Return the number of the player who is left last in the circle.
Example 1
people=4, step=3 → 1

Count 1, 2, 3: player 3 is out. Then 4, 1, 2: player 2 is out. Then 4, 1, 4: player 4 is out. Player 1 is left.

Example 2
people=6, step=1 → 6

Each count knocks out the player it starts on, so players leave in order and 6 is the last one standing.

Constraints
  • 1 ≤ step ≤ people ≤ 500
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDuel for the End Cards MediumA Deck That Reveals in Order MediumRiffle Shuffles Until the Deck Resets MediumRestore the Lost Dice MediumTop of the Digit Pyramid Medium
loading Python…
Input
people=4, step=3
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.