Leetcode Problem 2682. Find the Losers of the Circular Game

2682. Find the Losers of the Circular Game

Leetcode Solutions

Simulation with Visited Array

  1. Initialize a boolean array visited of size n to keep track of friends who have received the ball.
  2. Set visited[0] to true since the first friend starts with the ball.
  3. Initialize currentPosition to 0 and passCount to 1.
  4. While the friend at currentPosition has not been visited: a. Mark the friend at currentPosition as visited. b. Calculate the next position using (currentPosition + (passCount * k)) % n. c. Increment passCount.
  5. After the loop, count the number of friends who have not been visited.
  6. Initialize an array losers to store the indices of the friends who never received the ball.
  7. Iterate over the visited array and for each false value, add the index + 1 to the losers array.
  8. Return the losers array.
UML Thumbnail

Brute Force with HashSet

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...