Skip to content
LC-2996 Easy LeetCode

2996. Smallest Missing Integer Greater Than Sequential Prefix Sum

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 34% Topics: Array, Hash Table, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

# hash table
class Solution(object):
    def missingInteger(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        total = nums[0]
        for i in xrange(1, len(nums)):
            if nums[i] != nums[i-1]+1:
                break
            total += nums[i]
        lookup = set(nums)
        while total in lookup:
            total += 1
        return total

Solution from kamyu104/LeetCode-Solutions · MIT