3255. Find the Power of K-Size Subarrays II Medium

@problem@discussion
#Array#Sliding Window



1/**
2 * [3255] Find the Power of K-Size Subarrays II
3 *
4 * You are given an array of integers nums of length n and a positive integer k.
5 * The power of an array is defined as:
6 * 
7 * 	Its maximum element if all of its elements are consecutive and sorted in ascending order.
8 * 	-1 otherwise.
9 * 
10 * You need to find the power of all <span data-keyword="subarray-nonempty">subarrays</span> of nums of size k.
11 * Return an integer array results of size n - k + 1, where results[i] is the power of nums[i..(i + k - 1)].
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,2,3,4,3,2,5], k = 3</span>
16 * Output: [3,4,-1,-1,-1]
17 * Explanation:
18 * There are 5 subarrays of nums of size 3:
19 * 
20 * 	[1, 2, 3] with the maximum element 3.
21 * 	[2, 3, 4] with the maximum element 4.
22 * 	[3, 4, 3] whose elements are not consecutive.
23 * 	[4, 3, 2] whose elements are not sorted.
24 * 	[3, 2, 5] whose elements are not consecutive.
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [2,2,2,2,2], k = 4</span>
29 * Output: <span class="example-io">[-1,-1]</span>
30 * </div>
31 * <strong class="example">Example 3:
32 * <div class="example-block">
33 * Input: <span class="example-io">nums = [3,2,3,2,3,2], k = 2</span>
34 * Output: <span class="example-io">[-1,3,-1,3,-1]</span>
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	1 <= n == nums.length <= 10^5
40 * 	1 <= nums[i] <= 10^6
41 * 	1 <= k <= n
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-the-power-of-k-size-subarrays-ii/
47// discuss: https://leetcode.com/problems/find-the-power-of-k-size-subarrays-ii/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn results_array(nums: Vec<i32>, k: i32) -> Vec<i32> {
53        vec![]
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_3255() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.