Practice problems
Each problem gives you a starting file and a hidden test that compiles against your code. Write, run, and the page tells you exactly which assertion failed. Progress is stored in this browser.
Difficulty
Topic
- When the source is the destination What the compiler does for you Core
- Keep the length Arrays, and why they decay Core
- Counters without a lock Atomics and the memory model Core
- An average that is actually right Values, types, and names Warm-up
- Stop copying the argument References Warm-up
- Three searches that forget Recursion and backtracking Core
- Three relaxations with negative weights Bellman–Ford and Floyd–Warshall Core
- Three searches in the wrong order BFS, 0–1 BFS, and multi-source BFS Core
- Three masks that lose a bit Bitmasks: enumerating subsets and permutations Core
- Not every query is an AND Project: a small search index Stretch
- Which bound did you want? Binary search: on a range, and on the answer Core
- Break the reference cycle Smart pointers Stretch
- Bridges and cut vertices DFS: components, cycles, bridges Stretch
- Compressed adjacency, off by one Representing graphs Stretch
- The callback that allocates Zero-cost abstraction, examined Core
- Check at the boundary Undefined behaviour Core
- Name the invariant Invariants and assertions Core
- Classify without falling through Making decisions Warm-up
- Four comparators, three of them broken Sorting, comparators, and coordinate compression Core
- Is this version good enough? Dependencies and packaging Core
- Reject the bad literal at build time Compile-time computation Stretch
- What does this actually cost? Counting the work you actually do Core
- A billion values, a hundred thousand slots Sorting, comparators, and coordinate compression Core
- Make the class usable const and constness Core
- A table built before the program starts Compile-time computation Core
- Let the constraint choose Concepts and constraints Stretch
- The global that was not ready yet Headers, translation units, and linking Stretch
- A worker that can be told to stop Threads Core
- The frame outlives the call Coroutines Stretch
- Generic over the range and the test Function templates Core
- Make the allocations go away Measuring, not guessing Core
- Count the words std::string and text Core
- Three counters that lose track Hashing, frequency maps, and multisets Core
- Algorithms for free, from two members Static polymorphism Core
- A hash that does not collide Associative containers Stretch
- Two sweeps over a DAG Topological order and DAG DP Core
- Return exactly what you were given Deduction and forwarding Core
- Make the copy independent Copying Stretch
- Three windows that see too much Deques and sliding-window extrema Core
- Three depth-first searches DFS: components, cycles, bridges Core
- Three shortest-path searches Dijkstra Core
- One function, five behaviours Type traits and metaprogramming Core
- Three recursions that combine wrongly Divide and conquer Core
- Two things a union-find can do Union-Find Stretch
- Three union-finds that lose count Union-Find Core
- Correct on the sample, wrong on the hidden tests How to read a problem and its limits Core
- Four returns, zero unnecessary work Copies, moves, and elision Core
- Erase while iterating Iterators Core
- Commit with a swap Exceptions Stretch
- Two rules you have to derive Greedy, and proving it with an exchange argument Stretch
- What CTest actually reads Build systems and CMake Core
- Chain the fallible steps Error handling without exceptions Stretch
- Exponentiation by squaring Divide and conquer Core
- Find a value in a range Pointers Core
- Four bugs, one function Undefined behaviour Stretch
- Make it compile Hello, machine Warm-up
- Four ways to fail at link time Headers, translation units, and linking Core
- Order the conditions Repetition Warm-up
- Three loops, in the wrong order Bellman–Ford and Floyd–Warshall Core
- Four folds, no loops Variadic templates Core
- Line up the columns Input, output, and formatting Warm-up
- A factory that adds nothing Deduction and forwarding Core
- Protect the invariant Structs and classes Core
- One function, every type Function templates Warm-up
- Three graphs read wrongly Representing graphs Core
- Three greedies sorted by the wrong key Greedy, and proving it with an exchange argument Core
- Three races and a deadlock Data races and mutexes Core
- Packing keys, and counting pairs Hashing, frequency maps, and multisets Core
- Four ways an input can be shaped The contest template and fast I/O Core
- Write it for every container Iterators Core
- Five threads, none of them joined Threads Core
- Every distance, once Bellman–Ford and Floyd–Warshall Core
- Balanced split How to read a problem and its limits Core
- Longest window with a bounded spread Deques and sliding-window extrema Stretch
- The closest subset sum Meet in the middle Stretch
- How many pieces, and how big DFS: components, cycles, bridges Core
- Connect and ask Union-Find Core
- Multiples in a range Counting the work you actually do Core
- How far from sorted Divide and conquer Core
- Routes through a network Topological order and DAG DP Core
- How many cheapest routes Dijkstra Stretch
- How many are smaller Sorting, comparators, and coordinate compression Core
- Does this dependency graph have a cycle? DFS: components, cycles, bridges Core
- Jobs with deadlines Greedy, and proving it with an exchange argument Stretch
- The degree of every vertex Representing graphs Core
- Every distinct arrangement, in order Bitmasks: enumerating subsets and permutations Core
- Distinct values in every window Hashing, frequency maps, and multisets Core
- The farthest village Tree DP and rerooting Core
- Fibonacci, modulo a prime Counting the work you actually do Core
- Quadruples that cancel Meet in the middle Core
- A multiset by hand Hashing, frequency maps, and multisets Core
- Counting a grid's edges Representing graphs Core
- Largest rectangle in a histogram Monotonic stacks Stretch
- Covering the points Greedy, and proving it with an exchange argument Core
- The k-th smallest, many times Binary search: on a range, and on the answer Core
- Words per line The contest template and fast I/O Core
- Longest run under a budget Two pointers and sliding windows Core
- Peak overlap Prefix sums and difference arrays Core
- Fewest steps through a maze BFS, 0–1 BFS, and multi-source BFS Core
- Shipping within D days Binary search: on a range, and on the answer Stretch
- Spread, over many test cases The contest template and fast I/O Warm-up
- Counting the queens Recursion and backtracking Core
- The farthest cell from any source BFS, 0–1 BFS, and multi-source BFS Core
- Is there a negative cycle? Bellman–Ford and Floyd–Warshall Core
- Cabling the town Minimum spanning trees Core
- Next greater element Monotonic stacks Core
- Components after each removal Union-Find Stretch
- A tower of exponents Divide and conquer Stretch
- Range sums, many of them Prefix sums and difference arrays Core
- Covering everything with the fewest sets Bitmasks: enumerating subsets and permutations Stretch
- Shortest covering window Two pointers and sliding windows Stretch
- The cheapest route Dijkstra Core
- Leaderboard Sorting, comparators, and coordinate compression Core
- Subsets that hit a target Recursion and backtracking Core
- Sum of n integers How to read a problem and its limits Warm-up
- Schedule the tasks, alphabetically Topological order and DAG DP Core
- How far is everywhere Tree DP and rerooting Core
- The lightest bridge you must cross Minimum spanning trees Stretch
- Sliding window maximum Deques and sliding-window extrema Core
- When the vertex is not a place Dijkstra Stretch
- Take from something infinite Ranges and views Stretch
- Four macros that are not functions Modules Core
- Three combines that miscount Meet in the middle Core
- Two caches that remember too much Recursion and backtracking Core
- Bounded workers, unbounded tasks Futures, promises, and tasks Stretch
- An interface the language enforces Modules Core
- Make it add up Operator overloading Core
- Move instead of copying Moving Stretch
- Three spanning-tree routines Minimum spanning trees Core
- Questions the tree answers Minimum spanning trees Stretch
- The leak on the exception path The stack and the heap Core
- Do not let it be ignored Error handling without exceptions Core
- Absence without sentinels optional, variant, and expected Core
- Absence with a reason optional, variant, and expected Core
- One template, one copy of the work Inlining, linking, and layout Core
- Four sums that do not fit How to read a problem and its limits Core
- Resolve the ambiguity Functions Core
- A buffer that cleans up after itself Constructors, destructors, and RAII Core
- A pair of your own Class templates Core
- Four tasks, four hundred milliseconds Futures, promises, and tasks Core
- Fix the signatures Functions Warm-up
- Words in the right order Project: a small search index Stretch
- One pointer wide Inlining, linking, and layout Stretch
- Which one is cheaper here Zero-cost abstraction, examined Core
- Collapse the temporaries Ranges and views Core
- Sum an array through a pointer Pointers Core
- Hold it, do not be it When not to use inheritance Core
- Three tables that are off by one Prefix sums and difference arrays Core
- Counting subarrays with a frequency map Prefix sums and difference arrays Core
- Print two lines Hello, machine Warm-up
- State a property Testing Stretch
- Handing data to another thread Atomics and the memory model Stretch
- Fix what the warnings found Your toolchain Warm-up
- Reduce it, then fix it Debugging Core
- Remove the duplicates Algorithms Core
- Three lines that make it quadratic Counting the work you actually do Core
- Three sweeps over a tree Tree DP and rerooting Core
- reserve is not resize Sequence containers Warm-up
- Predict the order Lifetime and scope Core
- Thirty-one copies in three functions Copies, moves, and elision Core
- Read past the bad input Input, output, and formatting Core
- Delete the boilerplate The rule of zero, three, and five Core
- Guard before you look Making decisions Warm-up
- The loop that runs forever Values, types, and names Core
- A guard for an unfriendly API Constructors, destructors, and RAII Stretch
- Search for the answer, not the value Binary search: on a range, and on the answer Stretch
- Dispatch, and do not slice Inheritance and virtual functions Core
- The shift that is not a division What the compiler does for you Core
- Stop copying into the member Moving Core
- Sort by two keys Operator overloading Core
- Counting subarrays by their extreme Monotonic stacks Stretch
- Match a family of types Class templates Stretch
- Half the items, twice Meet in the middle Stretch
- Split a line into fields std::string and text Core
- The reference that goes stale Sequence containers Core
- Three stacks that lose an element Monotonic stacks Core
- The library the build file builds Build systems and CMake Warm-up
- All or nothing Exceptions Stretch
- Fifty-six bytes of thirty-three Cache and data layout Core
- Subset sums, reused Bitmasks: enumerating subsets and permutations Core
- Off by one Repetition Warm-up
- What the fifteen numbers mean Measuring, not guessing Core
- Swap two values References Warm-up
- Safe methods, unsafe together Data races and mutexes Core
- The top three, without sorting everything Algorithms Stretch
- Three orders that are not quite topological Topological order and DAG DP Core
- Same answer, sequential order Cache and data layout Core
- What the tree looks like from here Tree DP and rerooting Core
- Trim without copying std::string and text Core
- Pairs, from both ends Two pointers and sliding windows Stretch
- One container, unrelated types Static polymorphism Stretch
- Give it a single owner Smart pointers Core
- One emplace, any constructor Variadic templates Stretch
- One of several shapes optional, variant, and expected Stretch
- Erase without invalidating Algorithms Core
- Delete it safely Inheritance and virtual functions Core
- Three windows that slip Two pointers and sliding windows Core
- Two windows that need a second deque Deques and sliding-window extrema Stretch
- Count without inserting Associative containers Core
- One file that knows about the library Dependencies and packaging Core
- Say what you require Concepts and constraints Core
- Three lazy sequences Coroutines Core
- A trait of your own Type traits and metaprogramming Core
- Find the bug with a test Testing Core
- Deques, and the cost of an edge BFS, 0–1 BFS, and multi-source BFS Stretch
No problems match those filters yet.