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 -
while(left < right )
while(left <=right )
Using Method 1 -
- Search Condition needs to access element's immediate right neighbor
- Use element's right neighbor to determine if condition is met and decide whether to go left or right
- 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 ?