import sys, json

class Solution:
    def firstMissingPositive(self, nums: list[int]) -> int:
        nums.sort()
        missing = 1
        i = 0
        while i < len(nums):
            if nums[i] <= 0:
                i += 1
                continue
            if nums[i] != missing:
                break
            i += 1
            missing += 1
            while i < len(nums) and nums[i] == nums[i - 1]:
                i += 1

        return missing

data = json.loads(sys.stdin.read())
result = Solution().firstMissingPositive(data["nums"])
print(result)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: