2996. Smallest Missing Integer Greater Than Sequential Prefix Sum Easy
1/**
2 * [2996] Smallest Missing Integer Greater Than Sequential Prefix Sum
3 *
4 * You are given a 0-indexed array of integers nums.
5 * A prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.
6 * Return the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: nums = [1,2,3,2,5]
11 * Output: 6
12 * Explanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
13 *
14 * <strong class="example">Example 2:
15 *
16 * Input: nums = [3,4,5,1,12,14,13]
17 * Output: 15
18 * Explanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= nums.length <= 50
24 * 1 <= nums[i] <= 50
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum/
30// discuss: https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn missing_integer(nums: Vec<i32>) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_2996() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.