C++ practice problems
Solve in the browser, get judged instantly. Every problem has hidden tests, hints, a full solution and a deep-dive breakdown — plus XP and badges as you go, ordered from first steps to real algorithmic thinking.
How it works
- Pick a problem, write your solution in the editor on its page.
- Hit Judge (or press Ctrl+Enter in the editor) — your code runs against several test cases right in your browser, and you see exactly which tests passed; failures expand to show the input, the expected output and what your code actually printed.
- Need a do-over? Reset restores the starting template (it wipes your saved draft, so it asks first).
- Stuck? Expand the hints one at a time before looking at the full solution. Solved? The banner points you at the next problem — all sixty-five are ordered as one path.
Like everything on this site, judging runs locally in your browser — no account, no upload, nothing leaves your device. Drafts are saved automatically in your browser as you type. The good news: a runaway loop is stopped after 3 seconds instead of hanging the tab — a mistake costs you a few seconds, not a page reload.
65 problems
No problem matches — try another topic or clear the search.
Beginner
| Problem | Focus | |
|---|---|---|
| Sum of Two Numbers | Reading input, printing output | Start here |
| Say Hello | First read, first write | |
| Even or Odd | One modulus, one branch | |
| Absolute Value | Branching on the sign | |
| Swap Two Numbers | Why a swap needs a temporary | |
| Sort Three Numbers | Three compare-and-swaps | |
| Count Down | A for loop can go backwards | |
| Sum from 1 to N | Your first for loop | |
| Maximum of Three | if statements and comparisons | |
| Count the Digits | while loops and integer division | |
| Sum of Digits | The digit-chopping pattern, third lap | |
| Leap Year Check | &&/|| and edge-case reading | |
| Multiplication Table | Loops + exact output formatting | |
| Reverse a String | Strings, char arrays | |
| Count the Vowels | char inspection, cctype | |
| Run-Length Encoding | One pointer, self-ending runs |
Easy–medium
| Problem | Focus | |
|---|---|---|
| Reverse a Number | Digits, % and / together | |
| Palindrome Number | Recognizing a pattern you already own | |
| Armstrong Number | Counting digits, then raising each to that power | |
| Star Pyramid | Nested loops, output formatting | |
| Factorial | Accumulation, int overflow ceiling | |
| Maximum in an Array | Arrays vs streaming, running max | |
| Even and Odd Count | Parallel counters, negative-number care | |
| Reverse the Words | Read the whole line, split, print backwards | |
| Climbing Stairs | First DP: the last move decides the recurrence |
Medium
| Problem | Focus | |
|---|---|---|
| Prime Check | Loop logic, early exit, √N shortcut | |
| Count the Primes | Sieve of Eratosthenes — memory for speed | |
| Greatest Common Divisor | Euclid's algorithm, the first classic | |
| Least Common Multiple | Reusing gcd — and why divide before multiply | |
| Fibonacci Number | Sliding pair, recursion vs iteration | |
| Binary Representation | Bits, stash-and-reverse with arrays | |
| Sum a Matrix | 2D arrays, nested loops | |
| Is It a Power of Two? | Shrinking loop, bit trick | |
| Digit Frequency | Counting arrays | |
| Bit Count (popcount) | Bits, Kernighan's trick | |
| Minimum Coins | Greedy: take the biggest that fits | |
| Balanced Brackets | Array-as-stack, push and pop | |
| Generate Subsets | Bitmask: every subset is a binary number | |
| 2D Range Sums | Inclusion-exclusion on four corners | |
| Minimum Path Sum | First 2D DP: two pasts per cell | |
| Days Between Dates | Leap rules + serial day numbers | |
| Matrix Multiplication | Triple loop, one shared index | |
| Spiral Order | Four shrinking boundaries, two re-checks | |
| The Josephus Circle | Simulation: alive array + modulo walking |
Algorithm thinking
| Problem | Focus | |
|---|---|---|
| Second Largest | Tracking two values in one pass | |
| Two-Sum Exists | Every pair once — nested loops with j > i | |
| Collatz Steps | Simulating a rule nobody can solve | |
| Count the Words | Scanning a string with a state flag | |
| Bubble Sort | Compare and swap, in place | |
| Binary Search | Halving a sorted range, and the boundaries | |
| Maximum Subarray Sum | One pass, one carried value | |
| Palindrome String | Walking from both ends at once | |
| Matrix Transpose | Which index is the row? | |
| Base Conversion | Divide, take the remainder, reverse | |
| Counting Sort | Trading comparisons for memory | |
| Tower of Hanoi | Trusting a function before you've finished writing it | |
| Trailing Zeros | Replacing computation with counting | |
| Range Sum Queries | Prefix sums: pay once, query in O(1) | |
| All Permutations | Backtracking: choose, recurse, un-choose | |
| Merge Intervals | Sort first, then one sweep with a running end | |
| Minimum Waiting Time | Greedy proven by exchange argument | |
| Coin Change | DP where greedy fails: {1,3,4} for 6 | |
| Generate Parentheses | Backtracking with pruning counters | |
| 0/1 Knapsack | The loop direction decides reuse | |
| Longest Increasing Subsequence | Best chain ending here, O(n²) |
Good to know before you start
- Output must match exactly — same characters, same lines (trailing spaces and the final newline don't matter).
- Problems are solvable with the beginner toolbox:
cin/cout,if, loops, arrays and functions — same subset covered by our lessons and explained in the articles. - After solving, level up the same problem: can you make Sum from 1 to N O(1) with a formula? Can Prime Check skip even numbers?