Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Don't understand why it returns nums.length + 1 at the end? For which input woul...

Gary

Apr 1, 2022

Don't understand why it returns nums.length + 1 at the end? For which input would this line be needed?

1

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

We "return i + 1" as soon as we find a missing number. But if we can't find any element in the array, which will happen when the array is filled with all the initial positive numbers, then we have to return the next possible positive number.

For example, if the array'...

G
Gary 4 years ago

Thank you!

On this page