Back to Month
EASY 11 Aug 2026 View on LeetCode

2996. Smallest Missing Integer Greater Than Sequential Prefix Sum

</> Solution

class Solution {
    public int missingInteger(int[] nums) {
        int n = nums.length;
        int sum = nums[0];
        int i = 1;
        while (i < n && nums[i] == nums[i - 1] + 1) {
            sum += nums[i];
            i++;
        }

        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        while (set.contains(sum)) {
            sum++;
        }

        return sum;
    }
}

By CodeByTushu

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(n)

TOPICS

Array Hash Table Prefix Sum Simulation