Mastering STL in C++ for Efficient Coding

This week I stopped just solving problems and started actually understanding my tools. the thing nobody tells you early on: you can know the logic perfectly and still write terrible code because you're reinventing what already exists. that was me. so this week was all about STL C++ Standard Template Library. what is STL and why does it matter? STL is a collection of ready made data structures and algorithms built into C++. instead of manually building a hashmap or a dynamic array from scratch, you use what's already optimized and battle-tested. map, unordered_map, vector, stack, queue, set these aren't just containers. knowing which one to use and when is the difference between a clean O(n) solution and a messy O(n²) one. in a real interview, you don't have time to build from scratch. you need to know your tools. what I actually worked on this week: → map vs unordered_map ordered vs O(1) lookup tradeoffs → adjacency list using map<int, vector<int>> → prefix sum pattern → combining hashmap + modular arithmetic together problems solved: → LRU Cache (medium) finally understood how to combine hashmap + doubly linked list → Sum of Distances (medium) → Make Sum Divisible by P (medium) → Minimum Operations to Make Array Sum Divisible by K stuck on: LFU Cache LRU felt hard until it clicked. LFU is a whole different beast. still working on it. the honest part: "Make Sum Divisible by P" took me 2.5+ hours. I got TLE, then WA, fixed both, and finally understood why the solution works. slow? yes. but I didn't copy a solution I earned it. my LeetCode if you want to see the journey: https://lnkd.in/ghKx4CgM now a genuine question for the experienced folks here when you were learning DSA, how did you balance depth vs speed? spending 2-3 hours on one problem to fully understand it, or timebox it and move on? would love brutal honest takes. drop it in the comments 👇 #LeetCode #DSA #CPP #STL #LearningInPublic #BackendDevelopment #SoftwareEngineering #100DaysOfCode

To view or add a comment, sign in

Explore content categories