Tap here to switch tabs
Problem
Submissions

Problem: Find the Winner of an Array Game

med
30 min
Try to solve the Find the Winner of an Array Game problem.

Statement

Given an array of distinct integers arr and an integer k.

A game is played between the first two elements of arr. In each round:

  • The larger of arr[0] and arr[1] wins and remains at index 00.

  • The smaller element loses and is moved to the end of arr.

The game continues until an element achieves k consecutive round victories.

Return the integer that wins the game.

Note: It is guaranteed that a winner exists.

Constraints:

  • 2≤2 \leq arr.length ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤106\leq 10^6

  • arr contains distinct integers.

  • 1≤1 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Winner of an Array Game

med
30 min
Try to solve the Find the Winner of an Array Game problem.

Statement

Given an array of distinct integers arr and an integer k.

A game is played between the first two elements of arr. In each round:

  • The larger of arr[0] and arr[1] wins and remains at index 00.

  • The smaller element loses and is moved to the end of arr.

The game continues until an element achieves k consecutive round victories.

Return the integer that wins the game.

Note: It is guaranteed that a winner exists.

Constraints:

  • 2≤2 \leq arr.length ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤106\leq 10^6

  • arr contains distinct integers.

  • 1≤1 \leq k ≤109\leq 10^9