← Search

Micro-Drill #274 — Find peak element (binary search)

Search Target: 10s

Move toward the higher neighbor — a peak must exist on that side. Uses lo < hi (not <=) and hi = mid (not mid-1).

lo, hi = 0, len(a) - 1
while lo &lt; hi:
    mid = (lo + hi) // 2
    if a[mid] &lt; a[mid + 1]:
        lo = mid + 1
    else:
        hi = mid
return lo

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #273