title: Binary search, when to use right = mid - 1, and when to use right = mid?
body: <p>I was working through this problem on leetcode <a href="https://leetcode.com/problems/leftmost-column-with-at-least-a-one/" rel="noreferrer">https://leetcode.com/problems/leftmost-column-with-at-least-a-one/</a> and I cant think of an intuitive answer.</p>
  <p>Why is the right (or high) pointer sometimes set to mid - 1, and why is it sometimes correct to set to mid?</p>
  <p>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.</p>
  <p>But what are the cases to use right = mid - 1, vs right = mid?</p>
  <p>Thanks.</p>