Skip to main content

Practice ยท 2 of 4

Binary search

CHALLENGE
Difficulty: beginner+25 XP

Implement static int BinarySearch(int[] sorted, int target) โ€” return the index of target in the ascending array, or -1. Keep the invariant: if the target exists, it stays within [lo, hi].

Back to lesson: Practice: Algorithm workshop