You are given an array arr[] of size n - 1, containing distinct integers ranging from 1 to n (inclusive), except one missing element. The task is to find and return the missing integer from the range.
Example 1
Input: arr[] = [1, 2, 3, 5]
Output: 4
Explanation: All the numbers from 1 to 5 are present except 4.
Example 2
Input: arr[] = [8, 2, 4, 5, 3, 7, 1]
Output: 6
Explanation: All the numbers from 1 to 8 are present except 6.
Example 3
Input: arr[] = [1]
Output: 2
Explanation: Only 1 is present so the missing element is 2.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 3 5
4
8 2 4 5 3 7 1
6
1
2
4 3 5 7 1 6
2