How to find 4 byte number that was absent in input?
<p>I have such task, and actually have no idea how to start.
On the input I have a huge array of 4-byte positive numbers. Numbers can be repeated. I know that one of the number is not included in the input array. How can I find this number, using minimum resources?</p>

<p>The simplest code to do so, would probably be (in pseudo code):</p>

<pre><code>function find_missing(input)
    sort!(input)   # in-place sort, should take most of the time
    val = 0
    for d in input    # go over sorted input
        if d == val
            val += 1
        end
        if d &gt; val
            break
        end
    end
    return val
end
</code></pre>

<p>The above function should return the missing value or zero (in case there are no missing values because of wrap around of integers). If the missing value is zero, there is a bit of a confusion but the fix is simple and left to the reader.</p>

<p>Note: this is not the fastest method. Faster methods would use multiple passes to split up the input to subsets and analyze these subsets using the maximum available memory.</p>

python algorithm