2653. Sliding Subarray Beauty Medium

@problem@discussion
#Array#Hash Table#Sliding Window



1/**
2 * [2653] Sliding Subarray Beauty
3 *
4 * Given an integer array nums containing n integers, find the beauty of each subarray of size k.
5 * The beauty of a subarray is the x^th smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.
6 * Return an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.
7 * 
8 * 	
9 * 	A subarray is a contiguous non-empty sequence of elements within an array.
10 * 	
11 * 
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: nums = [1,-1,-3,-2,3], k = 3, x = 2
16 * Output: [-1,-2,-2]
17 * Explanation: There are 3 subarrays with size k = 3. 
18 * The first subarray is [1, -1, -3] and the 2^nd smallest negative integer is -1. 
19 * The second subarray is [-1, -3, -2] and the 2^nd smallest negative integer is -2. 
20 * The third subarray is [-3, -2, 3] and the 2^nd smallest negative integer is -2.
21 * <strong class="example">Example 2:
22 * 
23 * Input: nums = [-1,-2,-3,-4,-5], k = 2, x = 2
24 * Output: [-1,-2,-3,-4]
25 * Explanation: There are 4 subarrays with size k = 2.
26 * For [-1, -2], the 2^nd smallest negative integer is -1.
27 * For [-2, -3], the 2^nd smallest negative integer is -2.
28 * For [-3, -4], the 2^nd smallest negative integer is -3.
29 * For [-4, -5], the 2^nd smallest negative integer is -4. 
30 * <strong class="example">Example 3:
31 * 
32 * Input: nums = [-3,1,2,-3,0,-3], k = 2, x = 1
33 * Output: [-3,0,-3,-3,-3]
34 * Explanation: There are 5 subarrays with size k = 2.
35 * For [-3, 1], the 1^st smallest negative integer is -3.
36 * For [1, 2], there is no negative integer so the beauty is 0.
37 * For [2, -3], the 1^st smallest negative integer is -3.
38 * For [-3, 0], the 1^st smallest negative integer is -3.
39 * For [0, -3], the 1^st smallest negative integer is -3.
40 *  
41 * Constraints:
42 * 
43 * 	n == nums.length 
44 * 	1 <= n <= 10^5
45 * 	1 <= k <= n
46 * 	1 <= x <= k 
47 * 	-50 <= nums[i] <= 50 
48 * 
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/sliding-subarray-beauty/
53// discuss: https://leetcode.com/problems/sliding-subarray-beauty/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58    pub fn get_subarray_beauty(nums: Vec<i32>, k: i32, x: i32) -> Vec<i32> {
59        vec![]
60    }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68
69    #[test]
70    fn test_2653() {
71    }
72}
73


Back
© 2025 bowen.ge All Rights Reserved.