Skip to main content

Practice · 1 of 2

Binary search: return the index

CHALLENGE
Difficulty: intermediate+25 XP

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.

Back to lesson: Practice: Algorithm practice