Skip to main content

Practice · 2 of 5

Binary search

CHALLENGE
Difficulty: beginner+25 XP

Implement int binarySearch(int[] arr, int target) on an ascending, duplicate-free array: the target's index or -1. Use the exam's exact loop (lo/hi/mid with mid = (lo+hi)/2).

Back to lesson: Practice: Search & sort reps