Find the Winner of an Array Game
Updated
Problem 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.
More Goldman Sachs Online Assessment questions
- Maximum Ones After K OperationsOA · Seen Nov 2026
- Palindrome CounterOA · Seen Oct 2026
- Longest Palindromic SubsequenceOA · Seen Oct 2026
- Count Redundant File BackupsOA · Seen Oct 2026
- Minimum Distinct Prefix CostOA · Seen Oct 2026
- Merge Overlapping IntervalsOA · Seen Sep 2026
- Data ReorganizationOA · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsOA · Seen Jul 2026
- Minimum Number of Taps to Water a GardenOA · Seen Jun 2026
Similar questions at other companies
- Payment Partner RoutingStripe · OAStripe interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions