how to approach binary search problem
tags: learning leetcode programming
content
- think about the range for the binary search (left and right pointers)
- Koko Eating Bananas: what’s the maximum eating speed, and minimum eating speed
- Capacity to Ship Packages Within D Days: what’s the maximum capacity, what’s the upper/lower bound for my binary search
- what’s the criteria for moving pointers
- Capacity to Ship Packages Within D Days: construct a condition to know when to move left pointer and when to move right
- when moving pointers, should i discard
mid- Find Minimum in Rotated Sorted Array: will
midpotentially be the answer?
- Find Minimum in Rotated Sorted Array: will
- bounds:
while left < rightvswhile left <= right- when to use which? what’s the meaning behind these two?
while left < right:leftandrightconverges; when loop breaks,left == right