Doubts Regarding Binary Search

Revision en2, by DumbCarlsen69, 2021-05-25 02:26:12

Hello Everyone, Can anyone clarify when we are using binary search. Sometimes in the while loop We write while(l<r) and sometimes we write while (l<=r) depending from question to question ofc.

But I always get pretty confused between the two and ended up either wasting too much time or making many wrong submissions. is there a clear cut distinction like when we should use the first one and when we should use the second one?

Questions like these confuses me a lot https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/

Thanks!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English DumbCarlsen69 2021-05-25 02:26:12 1 Tiny change: ' write ** while(l<r)' -> ' write **while(l<r)'
en1 English DumbCarlsen69 2021-05-25 02:25:24 698 Initial revision (published)