A colleague read '10 C++ optimization tips' and swapped resize for reserve — 'it's faster'. The function now returns an empty vector, but very quickly. The sanitizer lights up red: writes past the size. Explain the difference between capacity and size to him — in code.
firstSquares calls reserve(n) and then writes through v[i] — but reserve only allocates capacity; the vector's size stays 0, so every v[i] is an out-of-bounds write (undefined behaviour) and the function returns an empty vector. Fix the growth.
push_back/emplace_back or resize — not bare v[i] after reserven elements: v[i] == i*in == 0 returns an empty vectorreserve(n) before push_back is encouraged (one allocation), just not requiredv[i] not bounds-check, and what would v.at(i) do here instead?reserve changes capacity; only resize/push_back change size. v[i] requires i < v.size().
Keep the reserve(n) and replace v[i] = … with v.push_back(i * i).
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.