Max Sliding Window
ARRAY
Problem
Given an array of integers nums
and an integer size
, representing the size of the sliding window, move the sliding window from the left end of the array to the right end.
You can only see the size
numbers in the window each time. The sliding window can move one position rightwards each time. Return an array that contains the maximum value of each window of the given size.
Examples
maxSlidingWindow([1,2,-2,-4,6,4], 2); // returns [2,2,-2,6,6] /* [1,2],-2,-4,6,4 --> max: 2 1,[2,-2],-4,6,4 --> max: 2 1,2,[-2,-4],6,4 --> max: -2 1,2,-2,[-4,6],4 --> max: 6 1,2,-2,-4,[6,4] --> max: 6 returns [2,2,-2,6,6] */
Loading...