Problem, as an interviewer would state it:
"Given an array of n distinct numbers taken from 0..n, exactly one number is missing. Find it. Discuss edge cases, runtime, and alternative approaches."
Examples:
findMissing([3, 0, 1]); // 2
findMissing([0, 1]); // 2
findMissing([1]); // 0
Clarifying questions expected:
- Is the input guaranteed to be distinct, in range, and missing exactly one value?
- Can I modify the array, and what space budget do I have?
- How large can
nbe (does the arithmetic stay exact)?
Code / implementation expected: Yes — real, direct proof of each approach, and of the input assumptions each one silently depends on.