Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Understanding what the target(s) of the binary search is, is important.

annejunkstuff

Sep 3, 2024

I was thrown off by the possibility of multiple zeros. I had to stop and think about why I should have known that I would need 2 binary searches. The answer of course is that we are targeting (as the solution states) the 'boundary between negative and positive'. And since we can have multiple zeros, the boundary between negative and zero is not always the same (or the same -/+ 1) as the boundary between zero and positive. Thus, we need two binary searches to find both possible targets.

1

0

Comments
Comments
W
willumeh a year ago

I understand the Binary search method is optimal, but it super confusing. I solved this using an Iterative approach and creating two list. One for negative and another for positive.

On this page