Stage 1 · Code
Arrays & Strings
Binary Search
Binary search on arrays, answer space, and rotated arrays.
Basic Binary Search
Binary Search — target: 13
Step 1 / 5 — Search for 13 in [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
Binary search finds target in sorted array in O(log n). Maintain left, right boundaries. Compute mid = left + (right-left)/2 to avoid overflow. Adjust boundaries based on comparison.
Lower/Upper Bound Variants
These variants are powerful for range queries, counting occurrences, and finding boundaries.
Binary Search on Answer Space
When the answer is a number with a monotonic property (if x works, all larger/smaller work), binary search the answer space instead of an array.
Search in Rotated Sorted Array
Array rotated at unknown pivot. One half is always sorted. Determine which half target lies in.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.