Find the missing number
The numbers 1 to N were written down, one was lost and the rest were shuffled. Given the N − 1 numbers that remain, print the missing one.
Reported in: Infosys (2021–26), Wipro Elite NTH, Accenture, Cognizant GenC, Deloitte (2025) (memory-based)
Input
First line: N. Second line: N − 1 distinct integers from 1 to N.
Output
The missing number.
Constraints
2 ≤ N ≤ 10^6.
Example 1
Input:
5
1 2 4 5
Output:
3Example 2
Input:
2
2
Output:
1Hint: The sum 1 + 2 + … + N is N(N+1)/2; subtract the sum of what you have.