Code Room
Code reviewHardcr-g172
Subject Iterator invalidationLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Review this C++ code holding a reference across map inserts.

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 <unordered_map>#include <string> void build(std::unordered_map<int, std::string>& m) {    std::string& slot = m[1];    slot = "one";    for (int i = 2; i < 100000; ++i) {        m[i] = std::to_string(i);    }    slot += "-final";}
Run or narrate your approach, then ask the coach.