Study Library
Read the full content of Master Competitive Programming with C++ — free, in your browser, chapter by chapter.
From Master Competitive Programming with C++ by RunTimeFix
All Chapters
Read front to back — each chapter builds on the last. Click any chapter to start reading.
C++ Foundations & Input/Output
Program Structure & Compilation · Variables & Data Types · Arithmetic Operations & Modulo · Integer Overflow & The 1LL Trick · Input/Output Streams & Fast I/O · Conditionals & Logical Operators
Loops & Direct Simulations
The Three Loop Structures · Loop Controls: break & continue · Nested Loops · Core Loop Patterns
Arrays, Strings & Character Operations
1D Arrays (C-Style) · 2D Arrays & Row-Major Layout · std::string & Character Operations
Functions & Recursion
Function Mechanics & Variable Scope · Parameter Passing: Value vs. Reference · Recursion & the Call Stack
Strings & Character Operations
std::string in C++ · Character Operations & ASCII Mathematics
Structs, Lambdas & Structured Bindings
Structures (Structs) in C++ · Lambdas & Inline Comparators · auto & Structured Bindings (C++17)
Preprocessor, Debug Macros & Compilation
The C++ Preprocessor & Macros · Compilation Pipeline & G++ Compiler Flags
Vectors, Pairs & Utility Algorithms
std::vector — The Dynamic Array · std::pair — Grouping Two Values · std::tuple — Grouping Three or More Values (D1) · String STL Methods (Advanced) · Iterators — The Bridge Between Containers and Algorithms · Utility Algorithms
Sets, Maps & Multi-Containers
std::set — Ordered Unique Elements · std::multiset — Ordered Elements with Duplicates · std::map — Key-Value Associations · std::unordered_map & std::unordered_set — Hash-Based Containers · std::stack — LIFO Container Adapter · std::queue — FIFO Container Adapter · std::deque — Double-Ended Queue · std::priority_queue — Heap-Based Container
Sorting & Frequency Arrays
std::sort — The Workhorse · lower_bound & upper_bound — Binary Search in STL · binary_search — Boolean Existence Check · unique — Removing Consecutive Duplicates · next_permutation — Generating Permutations · Sorting Applications · Frequency Counting
Complexity & Problem Solving
Reading Problem Statements · Complexity Analysis · Brute Force · Observation Finding · Edge-Case Handling · Debugging Techniques · Stress Testing
Basic Number Theory & Modular Arithmetic
Divisibility · GCD & LCM · Primes & Primality Testing · Sieve of Eratosthenes · Prime Factorization · Divisor Enumeration · Modular Arithmetic · Binary Exponentiation · Parity Arguments · Sum Formulas
Prefix Sums & Difference Arrays
1D Prefix Sums · 2D Prefix Sums · Suffix Sums & Suffix Aggregates · Difference Arrays
Two Pointers & Sliding Window
Two Pointers (Opposite Direction) · Two Pointers (Same Direction) · Sliding Window (Fixed Size) · Sliding Window (Variable Size)
Binary Search (Array & Answer Space)
Binary Search on a Sorted Array · STL Binary Search Functions · Binary Search on the Answer · Boundary Handling
Greedy Algorithms & Constructive Problems
The Greedy Paradigm · Sorting-Based Greedy · Interval Scheduling (Activity Selection) · The Exchange Argument · Constructive Algorithms
Bit Manipulation & Masking
Bitwise Operators · Bit Tricks · XOR Properties · Bitmask Enumeration · __builtin Functions
Stacks, Queues & Monotonicity
Stack Applications · Queue Applications · Monotonic Stack · Monotonic Deque (Sliding Window Min/Max)
Disjoint Set Union (DSU)
The Problem DSU Solves · Naive Implementation · Optimization 1: Path Compression · Optimization 2: Union by Rank/Size · Component Queries
Coordinate Compression, Fenwick Tree & Segment Tree
Coordinate Compression · Fenwick Tree (Binary Indexed Tree) · Segment Tree · Sparse Table (D1 — Recognition)
Graph Representation, DFS & BFS
Graph Terminology · Graph Representation · DFS on Graphs · BFS on Graphs · Connected Components · Grid Traversal
Cycle Detection, Bipartite Checking & Topological Sort
Cycle Detection in Undirected Graphs · Cycle Detection in Directed Graphs · Bipartite Checking · Topological Sort · DAG Reasoning · Functional Graphs
Dijkstra, 0-1 BFS & Kruskal's MST
Dijkstra's Algorithm · 0-1 BFS · Minimum Spanning Tree — Kruskal's Algorithm
Rooted Trees — DFS, Subtree Size & Diameter
Tree Terminology · Rooting a Tree · Tree Diameter · Distance Between Two Vertices · Tree Algorithms: Summary of Techniques
Binary Lifting, LCA & Euler Tour
Binary Lifting · Lowest Common Ancestor (LCA) · Euler Tour
Dynamic Programming — Foundations
The DP Paradigm · The DP Recipe · Classic DP Problems · Longest Increasing Subsequence (LIS) · Maximum Subarray Sum (Kadane's Algorithm)
Dynamic Programming — Knapsack & Subsets
The 0-1 Knapsack Problem · Unbounded Knapsack · Subset Sum & Knapsack Variants · Bitmask DP
Backtracking & Meet-in-the-Middle
The Backtracking Template · Generating Combinatorial Objects · Pruning · Meet-in-the-Middle
Modular Inverse, Combinatorics & Fast Math
Modular Multiplicative Inverse · Combinatorics: C(N, K) mod M · Common Combinatorial Problems · Matrix Exponentiation (Fast Math)
Hashing, String Algorithms & Geometry Basics
Polynomial Rolling Hashing · The Trie (Prefix Tree) · Geometry: The Cross Product · Book 1 Conclusion