~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Minimum spanning tree
Kruskal (sort edges + Union-Find) or Prim (heap).
Main path: 4 problems, about 75 min.
Notes
Recognise it when: you need to connect all points or cities at minimum total cost.
- Kruskal: sort the edges by weight and add each edge whose endpoints are in different Union-Find components. O(E log E).
- Prim: grow from a start node with a heap of edges leaving the tree. Good for dense graphs; an O(V^2) array version suits complete graphs such as "connect all points".
Gotchas: if the graph is disconnected there's no spanning tree, so check that you ended up with n-1 edges.
4 problems
Interview roadmap
Weighted graphs Dijkstra, union-find, spanning trees.
Minimum spanning tree guide
- Play first: The Road Builder 1-minute game Kruskal's algorithm (minimum spanning tree)
- Cheapest edge out of a group basics py · c++ · java easy
- Cheapest repairs to reconnect every city py · c++ · java medium
- Finish the irrigation network code the boss py · c++ · java medium
- Min Cost to Connect All Points py · c++ · java medium