~/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).
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
- Basics: Prim's algorithm with a heap basics py · c++ · java easy
- Finish the irrigation network py · c++ · java easy
- Min Cost to Connect All Points py · c++ · java medium
- Cheapest repairs to reconnect every city py · c++ · java easy