Search⌘ K
AI Features

Find Missing Number

Explore methods to identify the missing number in an array of positive integers from 1 to n. Understand naive, sorting-based, and optimal solutions that use the sum formula for natural numbers to achieve linear time and constant space complexity.

Statement

Given an array of positive numbers from 11 to nn, such that all numbers from 11 to nn are present except one number, xx, find xx. The input array is not sorted.

Example

For example, for n=7n = 7, let’s look at the below array, that is missing ...