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

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

Beginner

ProblemFocus
Sum of Two NumbersReading input, printing outputStart here
Say HelloFirst read, first write
Even or OddOne modulus, one branch
Absolute ValueBranching on the sign
Swap Two NumbersWhy a swap needs a temporary
Sort Three NumbersThree compare-and-swaps
Count DownA for loop can go backwards
Sum from 1 to NYour first for loop
Maximum of Threeif statements and comparisons
Count the Digitswhile loops and integer division
Sum of DigitsThe digit-chopping pattern, third lap
Leap Year Check&&/|| and edge-case reading
Multiplication TableLoops + exact output formatting
Reverse a StringStrings, char arrays
Count the Vowelschar inspection, cctype
Run-Length EncodingOne pointer, self-ending runs

Easy–medium

ProblemFocus
Reverse a NumberDigits, % and / together
Palindrome NumberRecognizing a pattern you already own
Armstrong NumberCounting digits, then raising each to that power
Star PyramidNested loops, output formatting
FactorialAccumulation, int overflow ceiling
Maximum in an ArrayArrays vs streaming, running max
Even and Odd CountParallel counters, negative-number care
Reverse the WordsRead the whole line, split, print backwards
Climbing StairsFirst DP: the last move decides the recurrence

Medium

ProblemFocus
Prime CheckLoop logic, early exit, √N shortcut
Count the PrimesSieve of Eratosthenes — memory for speed
Greatest Common DivisorEuclid's algorithm, the first classic
Least Common MultipleReusing gcd — and why divide before multiply
Fibonacci NumberSliding pair, recursion vs iteration
Binary RepresentationBits, stash-and-reverse with arrays
Sum a Matrix2D arrays, nested loops
Is It a Power of Two?Shrinking loop, bit trick
Digit FrequencyCounting arrays
Bit Count (popcount)Bits, Kernighan's trick
Minimum CoinsGreedy: take the biggest that fits
Balanced BracketsArray-as-stack, push and pop
Generate SubsetsBitmask: every subset is a binary number
2D Range SumsInclusion-exclusion on four corners
Minimum Path SumFirst 2D DP: two pasts per cell
Days Between DatesLeap rules + serial day numbers
Matrix MultiplicationTriple loop, one shared index
Spiral OrderFour shrinking boundaries, two re-checks
The Josephus CircleSimulation: alive array + modulo walking

Algorithm thinking

ProblemFocus
Second LargestTracking two values in one pass
Two-Sum ExistsEvery pair once — nested loops with j > i
Collatz StepsSimulating a rule nobody can solve
Count the WordsScanning a string with a state flag
Bubble SortCompare and swap, in place
Binary SearchHalving a sorted range, and the boundaries
Maximum Subarray SumOne pass, one carried value
Palindrome StringWalking from both ends at once
Matrix TransposeWhich index is the row?
Base ConversionDivide, take the remainder, reverse
Counting SortTrading comparisons for memory
Tower of HanoiTrusting a function before you've finished writing it
Trailing ZerosReplacing computation with counting
Range Sum QueriesPrefix sums: pay once, query in O(1)
All PermutationsBacktracking: choose, recurse, un-choose
Merge IntervalsSort first, then one sweep with a running end
Minimum Waiting TimeGreedy proven by exchange argument
Coin ChangeDP where greedy fails: {1,3,4} for 6
Generate ParenthesesBacktracking with pruning counters
0/1 KnapsackThe loop direction decides reuse
Longest Increasing SubsequenceBest chain ending here, O(n²)

Good to know before you start