← SAP questions

Find missing slot and number in 1 to 100 array

Filed under SAP

Free read 3 of 3

Use the arithmetic series formula n*(n+1)/2 to find the sum of all integers from 1 to 100.

The question

Given an array of size 100 containing numbers from 1 to 100 with exactly one missing number (represented by an empty slot or 0), identify the missing number efficiently.

Constraints

  • The array size is exactly 100.
  • Numbers are in the range [1, 100] with one value missing.

Examples

Input
nums = [1, 2, ..., 98, 99, 0]
Output
100
Why
The sum of 1 to 100 is 5050. The sum of the given array is 4950. The difference is 100.

Approach

  1. Use the arithmetic series formula n*(n+1)/2 to find the sum of all integers from 1 to 100.

Solution

O(N) time, O(1) space

Python
class Solution:
    def findMissing(self, nums: list[int]) -> int:
        # The sum of numbers from 1 to 100
        expected_sum = 100 * 101 // 2
        actual_sum = sum(nums)
        return expected_sum - actual_sum

Tips

  • What they are testing: Verify the solution with the first (1) or last (100) number missing to ensure boundary conditions are met.
  • Common mistake: Using a nested loop to check for each number from 1 to 100, which results in O(N^2) complexity instead of O(N).

Follow-ups

  • Write code and optimize it.

Related SAP questions

Collected from public candidate posts and coding forums. Updated Nov 2026.