I recently went through Binary Search Templates

https://leetcode.com/explore/learn/card/binary-search/

But I was not able to understand when to use -

  1. while(left < right )
  2. while(left <=right )

Using Method 1 -

  1. Search Condition needs to access element's immediate right neighbor
  2. Use element's right neighbor to determine if condition is met and decide whether to go left or right
  3. Post-processing required. Loop/Recursion ends when you have 1 element left. Need to assess if the remaining element meets the condition.

Can you explain this with some examples ?

Comments (1)