Find the target
Standard · Trace the algorithm · about 6 min
Follow binary search for 11 in 16 sorted primes. Before each step plays, say which half survives and which cell comes next.
Example 1
Input:
{"values":[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53],"target":11}
Output:
4
11 sits at index 4.
Constraints
- The trace uses the input shown.
- mid = (lo + hi) / 2, rounded down.
Learn the idea first: Binary search, a visual lesson.
More Binary search problems
- Mid values Warm-up
- Implement binary search Standard
- Fix the off-by-one Standard
- Square root floor Standard
- Search insert position Challenge