Last updated
Last updated
You are given an array of integers nums
, there is a sliding window of size k
which is moving from the very left of the array to the very right. You can only see the k
numbers in the window. Each time the sliding window moves right by one position.
Return the max sliding window.
Input: nums = [1]
, k = 1
Output: [1]
Doing a linear scan at each window step is a possible solution, but would take time to complete. A greedy solution does not work as the window size k
may vary. Hence, we use a queue to store the values from the previous window. This solution takes space and time.