Skip to content
RED SAG Skills
hardStudy question · answer published in JavaScript interview questions, so no pointssorting-and-searchingjavascript

Binary search loop that never ends

This search finds the last index where ok(i) is true. When does it loop forever?

while (lo < hi) {
  const mid = Math.floor((lo + hi) / 2)
  if (ok(mid)) lo = mid
  else hi = mid - 1
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions