Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
In the similar problem, why is it that "the best we can do is to skip one number...

Mike Xu

Jan 7, 2023

In the similar problem, why is it that "the best we can do is to skip one number from both ends"?

Thanks

0

0

Comments
Comments
M
Mike Xu3 years ago

Is it because we know that the same number has wrapped around the array, so we can safely ignore this number since it's not the same as our key. And to proceed, we can discard the number by shrinking our search range by 1 on each side.

Design Gurus
Design Gurus3 years ago

When 'start', 'end', and 'middle' all point to the same number value, we can't decide in which direction we should go or which half to ignore.

The best we can do, is to ignore the numbers at 'start' and 'end' and search again.

On this page