Code Room
Code reviewHardcr-g261
Subject Comparator violationsLevel Senior–Staff~25 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ comparator that treats two prices as equal when they are within an epsilon, otherwise orders them.

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
struct Quote { double price; int id; }; bool cmp(const Quote& a, const Quote& b) {    if (std::abs(a.price - b.price) < 1e-6) {        return false;            // "equal" -> not less    }    return a.price < b.price;} std::sort(quotes.begin(), quotes.end(), cmp);
Run or narrate your approach, then ask the coach.