Binary search on the answer, not on the input array.
Recognize that the minimum eating speed can be found by binary searching over the answer space from 1 to max(piles). For each candidate speed, compute the total hours needed using the ceiling division formula and check if it's ≤ h. The first feasible speed is the minimum.
Pro tip: Mention that the time complexity is O(n log m) where m is the maximum pile size, and that this is optimal because the feasibility check is monotonic. Also, explicitly state the ceiling division formula to show attention to detail.
The minimum speed is at least 1 and at most the size of the largest pile, since eating faster than the largest pile doesn't help. So set low = 1, high = max(piles).
For a given speed k, the hours needed for a pile of size p is ceil(p / k). Sum these hours over all piles and check if the total is ≤ h.
While low < high, compute mid = (low + high) // 2. If feasible(mid), set high = mid; else set low = mid + 1. Return low as the minimum speed.
The binary search takes O(log m) iterations, and each feasibility check takes O(n) time, giving O(n log m) total time and O(1) extra space.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.