Find Missing Number

Given an array of positive numbers from 1 to n, such that all numbers from 1 to n are present except one, find the missing number.

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 66:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.