The problem says that if you have n consecutive integers array and n-x, n-y and n-z values are missing from the array how we can find those numbers.
In case only one number would have been missing, its easier to find by summing the numbers in this array and comparing it with the sum of n consecutive integer array.
Now in case when two or more than two elements are missing, then the solution goes like this. Create another array of n size. Start putting 1 at the index position in new array which is equal to the value of the element in the old array. Example, if the first element value in the old array is 43, put 1 in the new array at the index position of 43. Like this populate the new array for all the elements in old array. Now the indexes with zero values in the new array are the missing values in the old array.
No comments:
Post a Comment