Problem · Array
Find the Winner of an Array Game
Learn this problemProblem statement
Distinct integers in arr play repeated rounds. Compare the first two values: the larger remains at the front, and the smaller moves to the end. The round winner's consecutive-win count increases; a different winner starts a new streak at one.
Return the first value to win k consecutive rounds.
Function
arrayGameWinner(arr: int[], k: int) → intExamples
Example 1
arr = [2,1,3,5,4,6,7]k = 2return = 5Five defeats 3 and 4 in consecutive rounds.
Example 2
arr = [3,2,1]k = 10return = 3Once the maximum reaches the front it can never lose.
Constraints
2 <= arr.length <= 1000001 <= k <= 10^9- Values are distinct signed 32-bit integers.