Loading problem…
You're building an analytics dashboard that displays maximum values in sliding time windows. For example, showing the maximum sales, page views, or user activity in each 5-minute window over the past hour.
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 maximum value in each sliding window.
maxSlidingWindow([1,3,-1,-3,5,3,6,7], 3);
// [3,3,5,5,6,7]
// Window positions:
// [1 3 -1] -3 5 3 6 7 -> max = 3
// 1 [3 -1 -3] 5 3 6 7 -> max = 3
// 1 3 [-1 -3 5] 3 6 7 -> max = 5
// 1 3 -1 [-3 5 3] 6 7 -> max = 5
// 1 3 -1 -3 [5 3 6] 7 -> max = 6
// 1 3 -1 -3 5 [3 6 7] -> max = 7This problem models real analytics features: