This question exist only because of pure curiosity. Not a homework.
Find the fastest way to find two missing number in an array 1..n
So, In a related post: Quickest way to find missing number in an array of numbers I found out that you can do this pretty quickly by summing up and substracting total.
but what about 2 numbers?
So, our options are:
- Sequential search
- Summing up items, substracting from total for all items from 1..n, then searching all possible cases.
Anything else? Possible to have O(n) solution? I found this in ruby section of one of the websites, but any language is considered (unless there are some specific things for a language)