Ctrl K

The Strongest Run

Easy
You get an array scores of distinct integers and a number size. Look at every run of the array (consecutive elements) of length exactly size and return the largest one. Runs are compared the way words are ordered in a dictionary: scan from the left to the first position where they differ, and the run with the bigger number there is larger. For example, [2, 7, 1] > [2, 5, 9] because 7 > 5 at the second position. See whether you can avoid comparing whole runs against each other.
Example 1
scores=[3, 8, 1, 9, 2, 5], size=3 → [9, 2, 5]

The runs of length 3 are [3, 8, 1], [8, 1, 9], [1, 9, 2] and [9, 2, 5]. They differ already at the first element, and [9, 2, 5] wins.

Example 2
scores=[3, 8, 1, 9, 2, 5], size=5 → [8, 1, 9, 2, 5]

There are only two candidates, [3, 8, 1, 9, 2] and [8, 1, 9, 2, 5]. The second is larger because 8 > 3.

Example 3
scores=[6, 4, 7], size=1 → [7]
Constraints
  • 1 ≤ size ≤ len(scores) ≤ 10⁵
  • 1 ≤ scores[i] ≤ 10⁹
  • All numbers in scores are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCake Slices for Guests EasyStrength of the Weaker Partner EasyPlanting Along a Garden Row EasyMaking Change at the Kiosk EasyRise and Fall Lineup Easy
loading Python…
Input
scores=[3, 8, 1, 9, 2, 5], size=3
Expected
[9, 2, 5]

Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.