FunctionRacerProblemsRace

Last Person Standing

MediumMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems