I was working through this problem on leetcode https://leetcode.com/problems/leftmost-column-with-at-least-a-one/ and I cant think of an intuitive answer.
Why is the right (or high) pointer sometimes set to mid - 1, and why is it sometimes correct to set to mid?
I am aware that we must always set left = mid + 1 because of integer division. When only two elements remain, we need to set mid + 1 to avoid an infinite loop.
But what are the cases to use right = mid - 1, vs right = mid?
Thanks.
right = mid-1
, if not (like python ranges) -right = mid
. – Heat