Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Smallest Missing Integer Greater Than Sequential Prefix Sum

XPChallenge Points: 10
levelLevel: Easy

You are given a 0-indexed integer array nums.

The prefix of the array is considered sequential if:

  • For every index j from 1 to i,
    nums[j] = nums[j - 1] + 1.

  • A single-element prefix (only nums[0]) is always considered sequential.

Your task is to:

  1. Identify the longest sequential prefix of the array.

  2. Calculate the sum of all elements in that prefix.

  3. Return the smallest missing integer in the array that is greater than or equal to this sum.

👉 Output: Return the first missing integer in the array that is ≥ the sum of the longest sequential prefix.

Example 1:

Input: nums = [4,5,6,10,11]

Output: 15

Explanation:

Longest sequential prefix = [4,5,6] Sum = 4 + 5 + 6 = 15 Array me 15 nahi hai → answer = 15

Example 2:

Input: nums = [2,3,4,7,8,9]

Output: 10

Explanation:

Sequential prefix = [2,3,4] Sum = 9 9 present hai → next number 10 10 not present → answer = 10

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result