2682. Find the Losers of the Circular Game
There are
nfriends that are playing a game. The friends are sitting in a circle and are numbered from1tonin clockwise order. More formally, moving clockwise from theithfriend brings you to the(i+1)thfriend for1 <= i < n, and moving clockwise from thenthfriend brings you to the1stfriend.The rules of the game are as follows:
1stfriend receives the ball.
- After that,
1stfriend passes it to the friend who isksteps away from them in the clockwise direction.- After that, the friend who receives the ball should pass it to the friend who is
2 * ksteps away from them in the clockwise direction.- After that, the friend who receives the ball should pass it to the friend who is
3 * ksteps away from them in the clockwise direction, and so on and so forth.In other words, on the
ithturn, the friend holding the ball should pass it to the friend who isi * ksteps away from them in the clockwise direction.The game is finished when some friend receives the ball for the second time.
The losers of the game are friends who did not receive the ball in the entire game.
Given the number of friends,
n, and an integerk, return the array answer, which contains the losers of the game in the ascending order.
1 | class Solution { |