2682. Find the Losers of the Circular Game
There are
n
friends that are playing a game. The friends are sitting in a circle and are numbered from1
ton
in clockwise order. More formally, moving clockwise from theith
friend brings you to the(i+1)th
friend for1 <= i < n
, and moving clockwise from thenth
friend brings you to the1st
friend.The rules of the game are as follows:
1st
friend receives the ball.
- After that,
1st
friend passes it to the friend who isk
steps away from them in the clockwise direction.- After that, the friend who receives the ball should pass it to the friend who is
2 * k
steps away from them in the clockwise direction.- After that, the friend who receives the ball should pass it to the friend who is
3 * k
steps away from them in the clockwise direction, and so on and so forth.In other words, on the
ith
turn, the friend holding the ball should pass it to the friend who isi * k
steps 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 { |