Skip to main content
Intermediate~6 min · +40 XP

Binary Search Step Count

Practices: Binary Search

Problem

Sorted array: [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] (10 elements, indices 0–9). You search for the target 91.

Binary search computes mid = ⌊(low + high) / 2⌋, compares, then halves the window.

How many comparisons until the target is found?

Examples

  • in: same array, target 16

    out: 1 comparison

    mid = ⌊(0+9)/2⌋ = 4, arr[4] = 16, first comparison hits.

Constraints & conventions

  • Each mid comparison counts once. Counting stops at the match.

Your answer

Solve the challenge to unlock the full approach and complexity analysis.