4 ms·
> missing - Takes an unsorted array of unique numbers (ie. no repeats), and returns the missing number in the sequence (there are either no missing numbers, or
by tzs 9y ago
> missing - Takes an unsorted array of unique numbers (ie. no repeats), and returns the missing number in the sequence (there are either no missing numbers, or exactly one missing number). Can you do it in O(N) time? Hint: There’s a clever formula you can use.
missing([1, 4, 3]) // 2
missing([5, 1, 4, 2]) // 3
missing([1, 2, 3, 4]) // undefined
I see some ambiguities there. Are they intentional to test the candidate? In particular:
Is the correct result for
missing([2,3,4])
undefined or 1?
What is the correct result for
missing([])
?
- bcherny 9y agoUpdated, good catch.