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.<p>Easy</p> <p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> friend for <code>1 <= i < n</code>, and moving clockwise from the <code>n<sup>th</sup></code> friend brings you to the <code>1<sup>st</sup></code> friend.</p> <p>The rules of the game are as follows:</p> <p><code>1<sup>st</sup></code> friend receives the ball.</p> <ul> <li>After that, <code>1<sup>st</sup></code> friend passes it to the friend who is <code>k</code> steps away from them in the <strong>clockwise</strong> direction.</li> <li>After that, the friend who receives the ball should pass it to the friend who is <code>2 * k</code> steps away from them in the <strong>clockwise</strong> direction.</li> <li>After that, the friend who receives the ball should pass it to the friend who is <code>3 * k</code> steps away from them in the <strong>clockwise</strong> direction, and so on and so forth.</li> </ul> <p>In other words, on the <code>i<sup>th</sup></code> turn, the friend holding the ball should pass it to the friend who is <code>i * k</code> steps away from them in the <strong>clockwise</strong> direction.</p> <p>The game is finished when some friend receives the ball for the second time.</p> <p>The <strong>losers</strong> of the game are friends who did not receive the ball in the entire game.</p> <p>Given the number of friends, <code>n</code>, and an integer <code>k</code>, return <em>the array answer, which contains the losers of the game in the <strong>ascending</strong> order</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 5, k = 2</p> <p><strong>Output:</strong> [4,5]</p> <p><strong>Explanation:</strong> The game goes as follows:</p> <ol> <li>Start at 1<sup>st</sup> friend and pass the ball to the friend who is 2 steps away from them - 3<sup>rd</sup> friend.</li> <li>3<sup>rd</sup> friend passes the ball to the friend who is 4 steps away from them - 2<sup>nd</sup> friend.</li> <li>2<sup>nd</sup> friend passes the ball to the friend who is 6 steps away from them - 3<sup>rd</sup> friend.</li> <li>The game ends as 3<sup>rd</sup> friend receives the ball for the second time.</li> </ol> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 4, k = 4</p> <p><strong>Output:</strong> [2,3,4]</p> <p><strong>Explanation:</strong> The game goes as follows:</p> <ol> <li>Start at the 1<sup>st</sup> friend and pass the ball to the friend who is 4 steps away from them - 1<sup>st</sup> friend.</li> <li>The game ends as 1<sup>st</sup> friend receives the ball for the second time.</li> </ol> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= k <= n <= 50</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • circularGameLosers

      public int[] circularGameLosers(int n, int k)