239. Sliding Window Maximum
First into mind now, priority queue
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
n = len(nums)
h = []
res = []
for i in range(n):
heappush(h, (-nums[i], i))
if i + 1 >= k:
while h[0][1] < i + 1 - k:
heappop(h)
res.append(-h[0][0])
return res
I used mono stack before (TBA)