CT015

Sliding Window Peaks

HardAcceptance: 0.0%

The watchmen of Codetikki scan the horizon through a window of fixed size k, sliding it across a row of mountain heights. At each position, they record the tallest peak visible in the window. Given an array of integers and a number k, compute the maximum value of each subarray of length k. Output the maximums as space-separated integers in O(n) time.

Example 1:

Input: 6 3 10 5 2 7 8 7
Output: 10 7 8 8

Example 2:

Input: 5 2 1 2 3 4 5
Output: 2 3 4 5

Constraints:

1 <= k <= n <= 10^5 -10^9 <= arr[i] <= 10^9

Tags:

queue sliding-window deque data-structures
Loading...
Test Cases:No test cases
No test cases available.