educative.io

Educative

Solution doesn't work for a n > nums.size() + 2

The solution (C++) doesn’t work for an array like this{2, 10, 2, 1} where missing numbers are larger than array size. In this case missing numbers 5, 6, 7, 8, 9 will not be found.

The input array should contain numbers from 1 to ‘n’. If the array can only have four numbers (this defines the ‘n’), the numbers can only be from the range 1-4 (10 is not a valid input).

1 Like

So “n” is the size of the array? I am not sure if the question specifies this? Or implies that the size of the array is “n”. Can someone clarify?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Find all Missing Numbers (easy) - Grokking the Coding Interview: Patterns for Coding Questions