Update appNew update is available. Click here to update.

Missing Number

Contributed by
Ratnesh
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share
3 upvotes

Problem Statement

There is an array ‘A’ of size ‘N’-1 with elements of range 1 to ‘N’.

The array does not contain duplicates.

You must return the only missing integer in range 1 to ‘N’.

For example:

Input:
A = [1, 2, 4, 5], N = 5
Output :
3
Explanation: 3 is the missing value in the range 1 to 5.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= N <= 10^5 
1 <= A[i] <= N
Time Limit: 1 sec
Sample Input 1 :
4 
1 2 3
Sample Output 1:
4
Explanation Of Sample Input 1:
Input:
A = [1, 2, 3], N = 4
Output:
4
Explanation: 4 is the missing value in the range 1 to 4.
Sample Input 2:
8
1 2 3 5 6 7 8
Sample Output 2:
4
Reset Code
Full screen
Auto
copy-code
Console