Class Solution
- java.lang.Object
-
- g2601_2700.s2682_find_the_losers_of_the_circular_game.Solution
-
public class Solution extends Object
2682 - Find the Losers of the Circular Game.Easy
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.Example 1:
Input: n = 5, k = 2
Output: [4,5]
Explanation: The game goes as follows:
- Start at 1st friend and pass the ball to the friend who is 2 steps away from them - 3rd friend.
- 3rd friend passes the ball to the friend who is 4 steps away from them - 2nd friend.
- 2nd friend passes the ball to the friend who is 6 steps away from them - 3rd friend.
- 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:
- Start at the 1st friend and pass the ball to the friend who is 4 steps away from them - 1st friend.
- The game ends as 1st friend receives the ball for the second time.
Constraints:
1 <= k <= n <= 50
- After that,
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]circularGameLosers(int n, int k)
-