Code RoomIterator erased during loop
HardPrep Room Coding #1793

Iterator erased during loop

Code reviewCode quality & reviewSenior–Staff~30 min

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.

0:00 of about 30 min
Mark a line and say what kind of problem it is.0 findings
1#include <map>
2#include <cstdint>
3 
4void prune(std::map<int, uint64_t>& sessions, uint64_t now) {
5 for (auto it = sessions.begin(); it != sessions.end(); ++it) {
6 if (it->second < now) {
7 sessions.erase(it);
8 }
9 }
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.