This is an interesting question I had come across a while ago and had some trouble solving it.
There's an unsorted integer array of size N stored with numbers 1,2..,N+M , with M integers missing from it. M and N are known before hand. Write an algorithm to find the missing M integers in the most efficient manner.
Had tried mapping it to an array of size N + M, so that the i th index contains the element with value i, but this requires 2 scans (1 for mapping, 1 for finding the M missing numbers).
The book in which I came across this mentions a single scan solution is possible but I was not able to arrive at it. Any ideas on how to go about this ?