Maximum sliding window value

Problem description

Given an integer array numS, there is a sliding window of size K that moves from the leftmost of the array to the rightmost of the array. You can only see k numbers in the sliding window. The sliding window moves only one bit to the right at a time.

Returns the maximum value in the sliding window.

Example 1:

Input: nums = [1, 3, 1, 3,5,3,6,7], k = 3 output:,3,5,5,6,7 [3] to explain: the position of the sliding window The maximum


[1 3-1] -3 5 3 6 7 3 1 [3-1-3] 5 3 6 7 3 1 3 [-1-3 5] 3 6 7 5 1 3-1 [-3 5 3] 6 7 5 1 3-1 [5 3 6 6] 7 6 1 3-1 5 [3 6 7] 7

To solve

Solution 1: Priority queue

A priority queue is not a queue. It is a small top heap