Code Room
Code reviewMedium
Question
Review this Java binary search. It is supposed to return the index of `target` or -1.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
static int search(int[] a, int target) { int lo = 0, hi = a.length; while (lo < hi) { int mid = (lo + hi) / 2; if (a[mid] == target) { return mid; } else if (a[mid] < target) { lo = mid; } else { hi = mid; } } return -1;}Run or narrate your approach, then ask the coach.