You are given an integer array containing 1 to n but one of the numbers from 1 to n in the array is missing. You need to provide the optimum solution to find the missing number.
The number cannot be repeated in the array.:
Solution:
- Find the sum of n number using formula n=n*(n+1)/2
- Find the sum of elements present in given array.
- Substract (sum of n numbers – sum of elements present in the array).
Java program to find missing number in an array:
When you run the above program, you will get the below output:

 
 
