Skip to main content

Practice ยท 1 of 2

Binary search: return the index

Implement int binary_search_index(const std::vector<int>& v, int target) returning the index of target in the **sorted** vector, or -1 when absent. Use the classic two-pointer loop with mid = lo + (hi - lo) / 2.

Difficulty: intermediate

Back to lesson: Practice: Algorithm practice