Find the Missing Number
Find the Missing Number
EasySorting30% accepted
Given N-1 distinct integers in the range 1 to N, find the one missing number. For example, if N=5 and the array is [1, 2, 4, 5], the missing number is 3. Use the sum formula: the sum of 1 to N is N*(N+1)/2. Subtract the array sum to get the missing number.
Approach
Given N and then N-1 integers from 1 to N, print the missing number.
Input
4
1 2 3 4
Output
5
More Sorting problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards