C++ Interview Guide β
A practical C++ reference for coding interviews β STL containers, algorithms, complexity analysis, and idiomatic patterns.
Why This Guide β
C++ is popular in interviews because of its explicit control over memory, rich STL, and predictable performance. But the language is also huge β this guide cuts it down to what you actually need for a technical interview: fast I/O, the right STL container for the job, the algorithms that handle 80% of problems, and the patterns you'll see over and over.
Every section includes time and space complexity so you can justify your choices during the interview.
Contents β
| # | File | Topic |
|---|---|---|
| 1 | 01-cpp-essentials | Modern C++ essentials β I/O optimization, auto, range-for, lambdas, structured bindings, pair/tuple, common gotchas |
| 2 | 02-stl-containers | vector, deque, list, string, stack, queue, priority_queue, set/map (ordered), unordered_set/unordered_map, bitset β with complexity tables |
| 3 | 03-stl-algorithms | sort, binary_search, lower_bound/upper_bound, reverse, rotate, unique, accumulate, count, find, min_element/max_element, partition, next_permutation β with complexity |
| 4 | 04-cpp-interview-patterns | Two pointers, sliding window, prefix sums, monotonic stack, BFS/DFS, binary search on answer, DP β idiomatic C++ |
Quick Reference β Pick the Right Container β
| Need | Container | Access | Insert | Search |
|---|---|---|---|---|
| Dynamic array | vector | O(1) | O(1) amortized back | O(n) |
| Queue both ends | deque | O(1) | O(1) front/back | O(n) |
| Sorted, unique | set | β | O(log n) | O(log n) |
| Sorted, keyβvalue | map | O(log n) | O(log n) | O(log n) |
| Hash, unique | unordered_set | β | O(1) avg | O(1) avg |
| Hash, keyβvalue | unordered_map | O(1) avg | O(1) avg | O(1) avg |
| LIFO | stack | top only | O(1) | β |
| FIFO | queue | front/back | O(1) | β |
| Max/min priority | priority_queue | top only | O(log n) | β |
| Bit flags | bitset | O(1) | β | β |
Quick Reference β Boilerplate β
cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// your solution here
return 0;
}Revision Checklist β
- [ ] Memorize complexity of every STL container operation
- [ ] Practice
lower_bound/upper_boundβ know they return iterators - [ ] Know when to use
unordered_mapvsmap(hash collisions, iteration order) - [ ] Understand when iterator invalidation happens (
vectoron realloc,erase) - [ ] Know the 3 ways to sort (ascending, descending, custom comparator)
- [ ] Be able to write BFS/DFS from scratch in under 3 minutes
- [ ] Know the
bits/stdc++.h+ fast I/O boilerplate cold
Cross-References β
| Topic | Where |
|---|---|
| DSA problems with C++ solutions | Amazon Prep DSA |
| Graph algorithms (DFS, BFS, Dijkstra) | Temple Prep Graphs |
| DP, Arrays, Strings, Trie | Temple Prep DSA Core |