Algorithm practice problems

Laddered easy, medium and hard coding problems for every algorithms topic, graded in your browser against hidden tests. Hints and Python + C++ solutions.

Arrays & strings

Searching

Recursion

  • Factorial (Easy) — Compute n! with a base case and a recursive step.
  • Fibonacci Number (Easy) — Return the n-th Fibonacci number (0-indexed).
  • Sum of Digits (Easy) — Add up the decimal digits of a non-negative integer.
  • Generate Parentheses (Medium) — All well-formed combinations of n pairs of parentheses.
  • Permutations (Hard) — Every ordering of a list of distinct integers.

Hashing

Stacks & queues

Sorting

Trees

Traversals

Linked lists

Pathfinding

Heaps

Dynamic programming

Bit manipulation

  • Single Number (Easy) — Every value appears twice except one — find it with XOR.
  • Counting Bits (Medium) — Popcount for every number 0..n in O(n) using a bit DP.

Math for algorithms

Greedy algorithms

Strings & pattern matching

Graphs

Divide & conquer

Game theory

Minimum spanning trees

  • Valid Spanning Tree (Easy) — Check whether undirected edges connect all n nodes without a cycle.
  • Minimum Connection Cost (Medium) — Return the MST weight of a weighted undirected graph, or -1 if disconnected.
  • Second Best MST (Hard) — Find the cheapest spanning tree whose total weight is strictly larger than the MST.