C++ is a fast, fully accepted interview language, and the STL covers almost every data structure the NeetCode 150 needs. The cost is a handful of sharp edges: a heap that is a max-heap by default, a map operator that inserts when you only meant to read, unsigned sizes and silent overflow. This page maps the list's 18 categories to the STL tools each one uses and lists the pitfalls that cost people time. For the list itself, see our NeetCode 150 roadmap; for language questions, our C++ interview questions.
The STL you need, by category
NeetCode 150 has 28 easy, 101 medium and 21 hard problems in these categories: arrays and hashing 9, two pointers 5, sliding window 6, stack 6, binary search 7, linked list 11, trees 15, heaps 7, backtracking 10, tries 3, graphs 13, advanced graphs 6, 1-D dynamic programming 12, 2-D dynamic programming 11, greedy 8, intervals 6, math and geometry 8, bit manipulation 7. Counts were read from each list's own site data in November 2026. Lists are edited from time to time, so numbers can drift.
| Tool | What to remember | Categories |
|---|---|---|
unordered_map, unordered_set | m[k] inserts a default value; use m.contains(k) (C++20) or find to test | Arrays and hashing, sliding window |
vector<int> cnt(26) | Faster than a map for lowercase letters: cnt[ch - 'a']++ | Anagrams, sliding window |
priority_queue | Max-heap by default; a min-heap is priority_queue<int, vector<int>, greater<int>> | Heaps, advanced graphs |
map, set | Ordered, O(log n), with lower_bound and upper_bound | Intervals, some greedy and design problems |
deque, queue, stack | queue and stack are adapters over deque; pop() returns nothing, so read front() or top() first | Trees, graphs, stack, sliding window maximum |
sort, lower_bound, iota | Comparators must be strict: return a < b, never a <= b | Intervals, greedy, binary search, union-find |
Category by category
- Arrays and hashing, two pointers, sliding window: pass vectors by reference (
const vector<int>&) so nothing is copied; for Longest Consecutive Sequence, build anunordered_setfrom the vector in one line and only start counting from numbers whose predecessor is missing. - Stack and binary search: compute the middle as
lo + (hi - lo) / 2; for 'search on the answer' problems such as Koko Eating Bananas, the sum of hours can exceedint, so accumulate inlong long. - Linked lists and trees: LeetCode hands you
ListNode*andTreeNode*; a dummy node on the stack (ListNode dummy;) avoids special cases and needs no cleanup. - Heaps: for Kth Largest, keep a min-heap of size k with
greater<int>; for custom ordering, pass a lambda withdecltype(cmp). The comparator says which element has lower priority, which is whylessgives a max-heap. - Backtracking: push, recurse, pop on one shared
vector; copy it into the result only when you record an answer. - Tries: an array of 26 child pointers per node is the usual interview version;
unique_ptrchildren avoid leaks if the interviewer asks. - Graphs and advanced graphs:
vector<vector<int>> adj(n)for adjacency; Dijkstra usespriority_queue<pair<int,int>, vector<pair<int,int>>, greater<>>with the distance first in the pair. - Dynamic programming:
vector<vector<int>> dp(m + 1, vector<int>(n + 1))zero-initializes; recursive memoized helpers are easiest as C++23 lambdas with an explicitthis auto&& selfparameter, or as a private member function. - Bit manipulation: LeetCode's current Reverse Bits and Number of 1 Bits take and return a plain
int(int reverseBits(int n)andint hammingWeight(int n)), and both inputs are non-negative;std::popcountfrom<bit>needs an unsigned type, so call it asstd::popcount(static_cast<unsigned>(n)), and__builtin_popcountworks on GCC and Clang. If an interviewer uses the olderuint32_tsignature, shift an unsigned value.
Pitfalls that cost time
- Unsigned sizes:
s.size() - 1on an empty string wraps to a huge number, andi < v.size() - 1loops forever. Cast tointfirst. - Overflow:
intis 32 bits on interview platforms;accumulate(v.begin(), v.end(), 0)sums inintbecause of the0, so write0LL. - Iterator invalidation:
push_backcan reallocate a vector and invalidate every iterator and reference into it; erasing from a map inside a loop must useit = m.erase(it). - Accidental inserts: reading
m[k]to check a count adds the key, which breaks size checks in sliding-window problems. substr(pos, len): the second argument is a length, not an end index, and each call copies; compare with indexes orstring_viewin hot loops.memset: only safe for 0 and -1 on integer arrays; usefillor vector constructors for anything else.
What LeetCode's C++ environment gives you
LeetCode compiles C++ with Clang 19 using the C++23 standard and the GCC 14 standard library, at optimization level -O2, with AddressSanitizer turned on, as LeetCode's help page on language environments listed it on November 11, 2026. Most standard headers are included automatically. AddressSanitizer is why an out-of-bounds read shows up as a 'heap-buffer-overflow' error instead of a wrong answer. Interview editors such as CoderPad or HackerRank may use a different compiler and standard, so ask which one before relying on C++20 or C++23 features like contains or ranges.
A six-week plan
- Week 1: arrays and hashing, two pointers and sliding window; get fluent with
unordered_mapand fixed-size count arrays. - Week 2: stack, binary search and linked lists; practise dummy nodes and overflow-safe midpoints.
- Week 3: trees and tries; write both recursive and iterative traversals with
stack<TreeNode*>. - Week 4: heaps, backtracking and graphs; write the min-heap declaration from memory.
- Week 5: advanced graphs and both dynamic programming categories.
- Week 6: greedy, intervals, math and bits, then mixed timed review.
The same plan with Python's tools is in NeetCode 150 in Python, and if you only have three weeks, the Blind 75 guide is the first half of NeetCode 150.
Turning a list into interview skill
Any list only helps if the practice transfers to problems you have not seen. These habits make the difference:
- Time-box every attempt: about 25 minutes for a medium before you read a solution.
- Keep a log with one line per problem: the pattern, the key idea and the complexity.
- Redo failed problems after three days, a week and three weeks, without looking at your old code.
- Explain your approach out loud before and while you code, as you would to an interviewer.
- In the last two weeks, switch to unseen problems without topic labels.
The patterns most lists are built on are explained in array and string patterns and tree, graph and recursion patterns.
Where CoPilot Interview fits
Finishing a list is not the same as passing an interview: interviewers score how you explain your approach, your trade-offs and your complexity out loud. CoPilot Interview is an AI interview assistant; its free AI mock interview asks coding questions, listens to your spoken explanation and scores it out of ten with a model answer, which is the part a problem list cannot train. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Online assessments and live coding rounds usually forbid outside help, so practice now and follow your employer's rules on the day.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.
Frequently asked questions
Is C++ a good language for NeetCode 150?
Yes. It is fast and fully accepted in interviews, and the STL covers heaps, ordered maps and hash maps. Code is longer than Python, so practise typing the common declarations.
How do I make a min-heap in C++?
Declare priority_queue<int, vector<int>, greater<int>>. The default priority_queue is a max-heap.
Which C++ version does LeetCode use?
Clang 19 with the C++23 standard and GCC 14's standard library, compiled at -O2 with AddressSanitizer, as LeetCode listed it in November 2026.
What are the most common C++ mistakes in coding interviews?
Unsigned size arithmetic, int overflow in sums, inserting into a map while only meaning to read, and using a non-strict comparator in sort.
Practice this interview before the real one
The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.
Start a mock interview