Code Room
Code reviewHardcr-g279
Subject Edge casesLevel Senior–Staff~18 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ loop that walks a buffer backwards to find the last non-zero byte.

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 lastNonZero(const std::vector<uint8_t>& buf) {    for (size_t i = buf.size() - 1; i >= 0; --i) {        if (buf[i] != 0) {            return static_cast<int>(i);        }    }    return -1;}
Run or narrate your approach, then ask the coach.