🌱SproutStack
👤 Guest

🌱 DSA (Beginner) · Core Patterns · cozy lesson

Binary Search

11 min · 1 min read · no scary math, promise

🤖
You’ve got this. Read a little, play a little — I’ll wait. No rush.
def bs(a, t):
    l, r = 0, len(a)-1
    while l <= r:
        m = l+(r-l)//2
        if a[m]==t: return m
        if a[m]<t: l=m+1
        else: r=m-1
    return -1

Pattern extends: first bad version, peak, “min max to ship” (search answer).

Check your understanding

Correct answers earn XP (once each).

1. Needs…

2. Mid overflow-safe?

My notes (saved in this browser)

Select text above → Save selection, or write your own. AlgoMaster-style notebook, local-first for MVP.

No notes yet. Your highlights will live here.

Finished reading? Seal it with a tick ✅

The checkbox in the explorer turns green too — same progress.