Skip to content
RED SAGSkills
medium30 ptsqueuesimulation

Circle Elimination Order

Players numbered 1 to n stand in a circle. Starting from player 1, count players around the circle; the player on whom the count reaches k is eliminated, and counting starts again at 1 from the next remaining player.

Return the players in the order they are eliminated.

Example 1

Input: n = 5, k = 2
Output: [2, 4, 1, 5, 3]

Example 2

Input: n = 3, k = 3
Output: [3, 1, 2]

Constraints

  • 1 <= n <= 5000
  • 1 <= k <= 10
Hint 1

Model the circle as a queue.

Hint 2

Move k - 1 players from the front to the back, then remove the front player.

Discussion 0

Join free to post in the discussion.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Game Developer

Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.