Last Person Standing
n people stand in a circle numbered 1 to n. Starting at person 1, count k people (person 1 is the first counted) and send the person you land on out of the circle, then continue counting from the next person still in. Repeat until one person remains, and return that person's number.
Example 1
n 5
k 2
returns 3
Out: 2, 4, 1, 5. Person 3 remains.
Constraints
1 <= n <= 201 <= k <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Minimum Moves to Equal ElementsMedium
- Multiply StringsMedium
- Power ModMedium
- Trailing Zeroes in FactorialMedium
- Twin PrimesMedium
- Valid SquareMedium
- Can the Pair Be ReachedHard
- Fewest Fuses to Find the Faulty ChipHard