From 3ms to 0ms: The Hidden Memory Trap in C++ Maps
From 3ms to 0ms: The Hidden Memory Trap in C++ Maps I thought I was writing the cleanest one-liner of my life. To solve Two Sum, I stored 1-based indices in an unordered_map so I could check for complements directly inside an if statement: if ( mp [ target - nums [ i ]]) { return { mp [ target - nums [ i ]] - 1 , i }; } It passed. But it took 3ms . On a whim, I swapped that single line to…
We haven't written up this one. Dev.to has the full story — the link below goes straight to it.