The common interview problem of determining the missing value in a range from 1 to N has been done a thousand times over. Variations include 2 missing values up to K missing val
I already answered it HERE
You can also create an array of boolean of the size last_element_in_the_existing_array + 1
.
In a for
loop mark all the element true
that are present in the existing array.
In another for
loop print the index of the elements which contains false
AKA The missing ones.
Time Complexity: O(last_element_in_the_existing_array)
Space Complexity: O(array.length)