Code Room
Code reviewHardcr-g158
Subject Iterator invalidationLevel Senior–Staff~30 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ loop that prunes expired entries.

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
#include <map>#include <cstdint> void prune(std::map<int, uint64_t>& sessions, uint64_t now) {    for (auto it = sessions.begin(); it != sessions.end(); ++it) {        if (it->second < now) {            sessions.erase(it);        }    }}
Run or narrate your approach, then ask the coach.