How to find a missing number from an array?
A Quick Overview
Problem Statement
Given an array of integers of size N – 1 ranging from 1 to N without any duplicates, the task is to find the missing number in the array.
Read More
Input:
list[] = {1, 2, 4, 6, 3, 7, 8, 10, 5}
Output:
9
Explanation:
The missing number from 1 to 10 is 9.
Example:
Read More
1. Calculate sum of the first N natural numbers as Total- N * (N + 1) / 2.
2. Calculate sum of elements of the array and store in a variable "Sum".
Simple Approach
Read More
3. Iterate array from start to end.
4. Update value of sum as sum = sum + array[i].
5. Print missing number as Total – sum.
Read More
Time Complexity:
O(N), where N is size of array.
Space Complexity:
O(1).
Read More
Check out other method with code implementation.
SWIPE UP