C++ practice
You strengthen your C++ by solving string, container, class and algorithm problems and test every solution with an automatic checker and sanitizers.
Level 201 · 18 lessons · 15 practice labs
Lessons
Basic exercises
- Exercise: string processing puzzles
- Exercise: sequences with vector
- Exercise: counting and grouping with map
- Exercise: recursion
- Exercise: a matrix class
- Short task: a mixed basics set
Classes and memory
- Exercise: an account class that keeps its invariants
- Exercise: shapes with virtual functions
- Exercise: a RAII file wrapper
- Exercise: replace raw pointers with smart pointers
- Exercise: fix the bugs the sanitizer catches
- Short task: a class design set
Algorithms and tools
- Exercise: an LRU cache
- Exercise: an expression parser and evaluator
- Exercise: shortest paths (Dijkstra)
- Exercise: the difference between two files
- Short task: a time-limited algorithm set
Capstone
- Capstone: five C++ problems that pass the automatic checker
Practice labs
- Encoding by shifting letters: Write a function that shifts letters by a given amount, wraps at the end of the alphabet and leaves non-letters alone.
- Rotating a vector in place: Rotate a vector k steps to the right without extra memory, passing the cases where k exceeds the size or is zero.
- Finding the longest substring without repeats: Find the longest substring without a repeated character in linear time with a sliding window and beat the time limit on large inputs.
- Grouping anagrams with a map: Group the anagrams in a word list in a map under a sorted-letter key and return the groups ordered by size.
- Counting regions in a grid with recursion: Count the regions of adjacent filled cells in a small two-dimensional grid using recursion.
- Adding safe multiplication to a matrix class: Add dimension-checked multiplication and transpose to a matrix class stored in a single vector, throw on mismatched sizes and pass the random tests.
- Keeping a fraction class reduced: In a fraction class reject a zero denominator, keep the sign out of the denominator and reduce after every operation.
- Keeping consistency in stock reserve and release: Define the invariants of a stock class that lets reservations exceed stock, throw on violation and test that state stays intact.
- A calendar class that rejects overlapping bookings: Write a class for Mercanköşk Otelcilik's hall calendar that rejects an overlapping booking in logarithmic time and show invariants hold after cancellations.
- Converting a raw array to a vector: Convert an array allocated with new[] and freed with delete to std::vector and show the sanitizer output is clean.
- Managing a lock file with RAII: Fix a tool that leaves its lock file behind on early returns and exceptions with a guard class that removes it in the destructor.
- Repairing three bugs the sanitizer catches: Find and repair one by one the out-of-bounds access, dangling reference and signed overflow that ASan and UBSan report in a small text tool.
- Finding the pair that gives a target sum: Find the two transactions whose amounts sum to the target in one pass with an unordered_map and return their indices.
- Writing a cache with expiry: Write a cache whose entries expire after a set time and whose oldest entry is evicted when full, testable with a fake clock.
- Finding the shortest route on a warehouse grid: Find the shortest route and its cost with a priority queue on a warehouse grid with weighted moves, report an unreachable target and beat the time limit.
About this course
You strengthen your C++ by solving string, container, class and algorithm problems and test every solution with an automatic checker and sanitizers.
What you will learn
- Basic exercises
- Classes and memory
- Algorithms and tools
- Capstone
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.