values and an integer k. Call the largest value in the whole array the peak.
Count the contiguous stretches of the array that contain the peak **at least k times**. Stretches with different boundaries count separately, even if they hold the same numbers.
Checking every stretch takes O(n²); aim for linear time.values=[2, 5, 1, 5, 5], k=2 → 6
The array maximum is 5. Six stretches contain it at least twice: [2, 5, 1, 5], [2, 5, 1, 5, 5], [5, 1, 5], [5, 1, 5, 5], [1, 5, 5] and [5, 5].
values=[3, 8, 2], k=2 → 0
There is only one 8, so no stretch can contain it twice.
values=[4, 4, 4], k=1 → 6
values=[2, 5, 1, 5, 5], k=2
6
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.