Skip to main content

Time Complexity · #3 · 2026-04-07

What's the Big-O?

JavaScript ·Difficulty 1/3

How to play

Read the code and pick its time complexity from four Big-O choices. Think about loops, recursion, and hidden costs. Press 1–4 or click to answer.

Sorted array of n elements. What is the time complexity?

function search(arr, target) {
  let lo = 0, hi = arr.length - 1;
  while (lo <= hi) {
    const mid = (lo + hi) >> 1;
    if (arr[mid] === target) return mid;
    if (arr[mid] < target) lo = mid + 1;
    else hi = mid - 1;
  }
  return -1;
}

Loading your progress...

Press 1 through 4, or tap a numbered choice, to answer. Back to hub