Leaving the circle
Write code · Challenge · §5.2 Queues
Students numbered 1 to n stand in a circle in order of their numbers. Counting starts from student 1, and the k-th student counted leaves the circle. Then the count starts over at 1 with the student right after the one who left.
This repeats until every student has left. Complete the function solution, which returns a list of the student numbers in the order the students leave.
Function
solution(n, k)
Constraints
nis an integer from 1 to 5,000.kis an integer from 1 to 1,000,000.
Examples
| n | k | result |
|---|---|---|
5 | 2 | [2, 4, 1, 5, 3] |
3 | 1 | [1, 2, 3] |
Starter code
def solution(n, k):
answer = []
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.