LeetCode 239 Sliding Window Maximum - Problem Statement

The problem

Given an array nums and a window size k, return an array of the maximum value in each sliding window as it moves from left to right.

With nums = [1, 3, -1, -3, 5, 3, 6, 7] and k = 3, the answer is [3, 3, 5, 5, 6, 7]. The first window [1, 3, -1] has max 3. The second window [3, -1, -3] also has max 3. And so on.

What data structure lets you find the maximum efficiently while the window slides?

Constraints: 1n1051 \le n \le 10^5, 1kn1 \le k \le n.