Code RoomEpsilon comparator not transitive
HardPrep Room Coding #1895

Epsilon comparator not transitive

Code reviewCode quality & reviewSenior–Staff~25 min

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.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1struct Quote { double price; int id; };
2 
3bool cmp(const Quote& a, const Quote& b) {
4 if (std::abs(a.price - b.price) < 1e-6) {
5 return false; // "equal" -> not less
6 }
7 return a.price < b.price;
8}
9 
10std::sort(quotes.begin(), quotes.end(), cmp);
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.