862. Shortest Subarray with Sum at Least K Hard

@problem@discussion
#Array#Binary Search#Queue#Sliding Window#Heap (Priority Queue)#Prefix Sum#Monotonic Queue



1/**
2 * [862] Shortest Subarray with Sum at Least K
3 *
4 * Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return -1.
5 * A subarray is a contiguous part of an array.
6 *  
7 * Example 1:
8 * Input: nums = [1], k = 1
9 * Output: 1
10 * Example 2:
11 * Input: nums = [1,2], k = 4
12 * Output: -1
13 * Example 3:
14 * Input: nums = [2,-1,2], k = 3
15 * Output: 3
16 *  
17 * Constraints:
18 * 
19 * 	1 <= nums.length <= 10^5
20 * 	-10^5 <= nums[i] <= 10^5
21 * 	1 <= k <= 10^9
22 * 
23 */
24pub struct Solution {}
25
26// problem: https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/
27// discuss: https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31impl Solution {
32    pub fn shortest_subarray(nums: Vec<i32>, k: i32) -> i32 {
33        0
34    }
35}
36
37// submission codes end
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_862() {
45    }
46}
47


Back
© 2025 bowen.ge All Rights Reserved.