Code Room
Code reviewHardcr-g454
Subject Integer overflowLevel Senior–Staff~18 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Review this C++ binary search over an index range that can include negative coordinates (e.g. a signed axis).

It is called with `lo` as low as INT_MIN and `hi` near INT_MAX.

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 reviewcpp
int search(const std::vector<int>& a, int lo, int hi, int target) {    while (lo <= hi) {        int mid = lo + (hi - lo) / 2;        if (a[mid] == target) return mid;        else if (a[mid] < target) lo = mid + 1;        else hi = mid - 1;    }    return -1;}
Run or narrate your approach, then ask the coach.