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.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.
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.
scores=[6, 4, 7], size=1 → [7]
scores are distinctscores=[3, 8, 1, 9, 2, 5], size=3
[9, 2, 5]
Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.