#2682
Find the Losers of the Circular Game
pupil · 455 · lc easy +26 · verified · 49.8% accepted · 256 likes · top 37%
Description
There are n friends seated in a circle numbered 1 to n clockwise. Friend 1 starts with the ball and passes it k steps clockwise; each subsequent pass increases the step count by k. The game ends when someone receives the ball a second time. Return the sorted list of friends who never received the ball.
Example 1:
Input: n = 5, k = 2
Output: [4,5]
Explanation: The game goes as follows:
1) Start at 1st friend and pass the ball to the friend who is 2 steps away from them - 3rd friend.
2) 3rd friend passes the ball to the friend who is 4 steps away from them - 2nd friend.
3) 2nd friend passes the ball to the friend who is 6 steps away from them - 3rd friend.
4) The game ends as 3rd friend receives the ball for the second time.
Example 2:
Input: n = 4, k = 4
Output: [2,3,4]
Explanation: The game goes as follows:
1) Start at the 1st friend and pass the ball to the friend who is 4 steps away from them - 1st friend.
2) The game ends as 1st friend receives the ball for the second time.
Code
1
2
3