First Champion to Win k Consecutive Array Comparisons
Quick Overview
First Champion to Win k Consecutive Array Comparisons. The array has distinct values. Each round compares its first two entries; the larger stays first and the smaller moves to the end.
First Champion to Win k Consecutive Array Comparisons
Company: Goldman Sachs
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
The array has distinct values. Each round compares its first two entries; the larger stays first and the smaller moves to the end. Stop when one value has won k consecutive rounds. Return that winning value.
```cpp
class Solution {
public:
int getWinner(vector<int>& arr, int k);
};
```
### Examples
**Example 1:**
```text
Input: arr = [1,4,2,3], k = 2
Output: 4
Explanation:4 first defeats1,then defeats2,and reaches two consecutive wins.
```
**Example 2:**
```text
Input: arr = [2,1,5], k = 100
Output: 5
Explanation:2 wins once before5 takes over. The global maximum5 can never lose and eventually reaches100 wins.
```
### Constraints
- arr contains 2 to 100000 distinct integers.
- `1 <= arr[i] <= 1000000`.
- `1 <= k <= 1000000000`.
- A winner is guaranteed.
### Contract considerations
Distinguish consecutive victories from total victories across separate streaks, and return the winning value rather than a round count.
```hint Read the boundary condition
Track consecutive victories under the stated round rules, including a change of champion and a large target streak. Return the winning value.
```
### Boundary reminders
Distinguish consecutive victories from total victories across separate streaks, and return the winning value rather than a round count.
Overview: First Champion to Win k Consecutive Array Comparisons. The array has distinct values. Each round compares its first two entries; the larger stays first and the smaller moves to the end.
First Champion to Win k Consecutive Array Comparisons
Goldman Sachs
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0
Problem
The array has distinct values. Each round compares its first two entries; the larger stays first and the smaller moves to the end. Stop when one value has won k consecutive rounds. Return that winning value.
class Solution {
public:
int getWinner(vector<int>& arr, int k);
};
Examples
Example 1:
Input: arr = [1,4,2,3], k = 2
Output: 4
Explanation:4 first defeats1,then defeats2,and reaches two consecutive wins.
Example 2:
Input: arr = [2,1,5], k = 100
Output: 5
Explanation:2 wins once before5 takes over. The global maximum5 can never lose and eventually reaches100 wins.
Constraints
arr contains 2 to 100000 distinct integers.
1 <= arr[i] <= 1000000
.
1 <= k <= 1000000000
.
A winner is guaranteed.
Contract considerations
Distinguish consecutive victories from total victories across separate streaks, and return the winning value rather than a round count.
Boundary reminders
Distinguish consecutive victories from total victories across separate streaks, and return the winning value rather than a round count.