Missing Number
Practice this coding question on Coding Gurukul.
Problem statement
A registration desk issued every badge number from 0 through n. Its reconciliation list contains n distinct badges, so exactly one issued number is missing from the list. Your task Find the single missing integer in the inclusive range 0 through n. Use O(n) time and O(1) additional space. Important details The missing number may be zero or n. Entries need not be sorted, but no entry appears twice. Do not assume the missing value lies between the minimum and maximum observed entries. Worked example For n = 3 and entries [3, 0, 1], the complete range is [0, 1, 2, 3]. Only 2 is absent.
Input format
The first line contains n. The next line contains n space-separated integers; for n = 0 this line may be empty.
Output format
Print the missing integer.
Constraints
1 <= n <= 10000; entries are distinct and satisfy 0 <= value <= n.
Sample input
3 3 0 1
Sample output
2
Sign in to run or submit a solution in C++, Java or Python.