Find the Winner of the Circular Game
Problem statement
Players numbered 1 through n stand in a circle. Starting with player 1, count k remaining players including the current player, eliminate that player, and resume with the next remaining player. Return the final survivor.
Function
findTheWinner(n: int, k: int) → intExamples
Example 1
n = 5k = 2return = 3The elimination order is 2, 4, 1, 5, leaving 3.
Constraints
1 <= n <= 500.1 <= k <= 10^9.