Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Overview

Halve the search space · then search answers, not arrays
step 1 / 7
1
3
5
7
9
11
13
[0][1][2][3][4][5][6]
Concept
1lo = 0, hi = n − 1 // candidates: arr[lo..hi]
2while lohi:
3 mid = (lo + hi) / 2
4 if arr[mid] == target: found!
5 if arr[mid] < target: lo = mid + 1
6 else: hi = mid − 1
7// each question halves the space → O(log n)
state
  • target9
  • n7

line 1Find 9 in a SORTED array. A linear scan checks one cell at a time — n questions worst case. Sortedness lets us ask a much better question: "is the middle too small or too big?"