Highest in Every Window
You are given a list of integers nums and a window size k. A window of k numbers in a row slides along the list one place at a time, from the start to the end. Return the highest number in every window, in order.
There are len(nums) − k + 1 windows, so the answer holds that many numbers.
Examples
nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3 → [3, 3, 5, 5, 6, 7]
nums = [4], k = 1 → [4]
nums = [9, 8, 7, 6], k = 2 → [9, 8, 7]
nums = [2, 2, 2, 2], k = 3 → [2, 2]In the first example the windows are [1, 3, -1], [3, -1, -3], [-1, -3, 5], [-3, 5, 3], [5, 3, 6] and [3, 6, 7].
Constraints
- Between 1 and 20,000 numbers, each between -10,000 and 10,000;
kis between 1 and the length of the list. - Aim for O(n): finding each window's highest from scratch costs n × k.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 8 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.