239. Sliding Window Maximum Hard

@problem@discussion
#Array#Queue#Sliding Window#Heap (Priority Queue)#Monotonic Queue



1/**
2 * [239] Sliding Window Maximum
3 *
4 * 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.
5 * Return the max sliding window.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
10 * Output: [3,3,5,5,6,7]
11 * Explanation: 
12 * Window position                Max
13 * ---------------               -----
14 * [1  3  -1] -3  5  3  6  7       3
15 *  1 [3  -1  -3] 5  3  6  7       3
16 *  1  3 [-1  -3  5] 3  6  7       5
17 *  1  3  -1 [-3  5  3] 6  7       5
18 *  1  3  -1  -3 [5  3  6] 7       6
19 *  1  3  -1  -3  5 [3  6  7]      7
20 * 
21 * Example 2:
22 * 
23 * Input: nums = [1], k = 1
24 * Output: [1]
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= nums.length <= 10^5
30 * 	-10^4 <= nums[i] <= 10^4
31 * 	1 <= k <= nums.length
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/sliding-window-maximum/
37// discuss: https://leetcode.com/problems/sliding-window-maximum/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn max_sliding_window(nums: Vec<i32>, k: i32) -> Vec<i32> {
43        vec![]
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_239() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.