HI...
Problem: If ‘n’ is the positive number and ‘a’ is an array of integers of length n-1 containing elements from 1 to n. Then find the missing number in ‘a’ in the range from 1 to n. Occurrence of each element is only once. i.e ‘a’ does not contain duplicates.
Example :
If n = 8, then array ‘a’ will have 7 elements in the range from 1 to 8. For example {1, 4, 5, 3, 7, 8, 6}. One number will be missing in ‘a’ (2 in this case). You have to find out that missing number.
Solution :
Step 1 : First we find out sum of ‘n’ numbers by using formula n*(n+1)/2.
Step 2 : Then we will find sum of all elements of array ‘a’.
Step 3 : Missing_Number = (Sum of 1 to ‘n’ numbers) – (Sum of elements of array ‘a’)
This solution is feasible for finding if any single number is missing from the array. What if multiple numbers are missing from our array. So how can we find? Thanks in advance Kindly help