Skip to content

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 ​

#FileTopic
101-cpp-essentialsModern C++ essentials β€” I/O optimization, auto, range-for, lambdas, structured bindings, pair/tuple, common gotchas
202-stl-containersvector, deque, list, string, stack, queue, priority_queue, set/map (ordered), unordered_set/unordered_map, bitset β€” with complexity tables
303-stl-algorithmssort, binary_search, lower_bound/upper_bound, reverse, rotate, unique, accumulate, count, find, min_element/max_element, partition, next_permutation β€” with complexity
404-cpp-interview-patternsTwo pointers, sliding window, prefix sums, monotonic stack, BFS/DFS, binary search on answer, DP β€” idiomatic C++

Quick Reference β€” Pick the Right Container ​

NeedContainerAccessInsertSearch
Dynamic arrayvectorO(1)O(1) amortized backO(n)
Queue both endsdequeO(1)O(1) front/backO(n)
Sorted, uniquesetβ€”O(log n)O(log n)
Sorted, key→valuemapO(log n)O(log n)O(log n)
Hash, uniqueunordered_setβ€”O(1) avgO(1) avg
Hash, key→valueunordered_mapO(1) avgO(1) avgO(1) avg
LIFOstacktop onlyO(1)β€”
FIFOqueuefront/backO(1)β€”
Max/min prioritypriority_queuetop onlyO(log n)β€”
Bit flagsbitsetO(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_map vs map (hash collisions, iteration order)
  • [ ] Understand when iterator invalidation happens (vector on 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 ​

TopicWhere
DSA problems with C++ solutionsAmazon Prep DSA
Graph algorithms (DFS, BFS, Dijkstra)Temple Prep Graphs
DP, Arrays, Strings, TrieTemple Prep DSA Core

Frontend interview preparation reference.