Code Room
Code reviewMediumcr-g263
Subject Integer overflowLevel Mid–Senior~18 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Review this Java binary search over a large array.

This runs fine in tests but the team has seen `ArrayIndexOutOfBoundsException` with very large arrays (near 2^30 elements) loaded from a memory-mapped file.

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.

Talk through your review
Code to reviewjava
int search(int[] a, int key) {    int low = 0, high = a.length - 1;    while (low <= high) {        int mid = (low + high) / 2;        if (a[mid] < key)      low = mid + 1;        else if (a[mid] > key) high = mid - 1;        else                   return mid;    }    return -1;}
Run or narrate your approach, then ask the coach.