Binary search doubt | Please help

For the question- https://leetcode.com/problems/koko-eating-bananas/
All of my test cases are passing for this question except for this one. And I fail to understand why exactly my approach used to solve this question is incorrect.
image

I saw the solution. they have considered high = mid and have iterated till low<high instead of low<=high. And they have returned the variable high. Rest all parts of the solution given andm y solution are exactly the same.

Most of the times I get confused in Binary search if I should take the while loop condition as low < high or low<=high
Similarly, I get confused if to put high = mid-1 and low = mid+1 or high = mid and low = mid
What is the best way to tackle this? Now, by looking at the test cases I can use trial and error to modify. However, in an interview I will have to answer why I did use mid+1 instead of mid or why I am returning high instead of let's say a mid or a low. So how to deal with the same?

Solution given by leetcode: https://leetcode.com/problems/koko-eating-bananas/solution/

#here's my code
low = 1
high = max(piles)

count = 0
final_k = 100000

while low <= high:
    mid_val = (low+high)//2
    count = 0
    
    for pile in piles:
        if pile > mid_val:
            count+=(pile//mid_val)+1
        else:
            count+=1
    
    if count>h:
        low = mid_val+1
        
    elif count<=h:
        final_k = mid_val
        high = mid_val-1

return final_k
Comments (1)