Ten problems that drill the weighted-graph algorithms from Lesson 23. The hardest part is recognising which algorithm the question is asking for; once you name it, the code is a template. Each solution here was actually run and tested.
How to practise. Before writing anything, say out loud which tool fits: non-negative weights and a single source → Dijkstra; bounded hops or negative edges → Bellman-Ford; all-pairs → Floyd-Warshall; “connect everything” → MST. Then reach for the template. If you can name the algorithm, you are 80% done.
The 10 problems
- 1Network Delay Time (LeetCode 743)MediumHow long until a signal from k reaches every node? Dijkstra from k; the answer is the largest distance.arrow_forward
- 2Cheapest Flights Within K Stops (LeetCode 787)MediumCheapest route from src to dst with at most k stops: run k+1 Bellman-Ford rounds, each on a snapshot.arrow_forward
- 3Path With Minimum Effort (LeetCode 1631)MediumFind the grid path whose biggest single height step is smallest: Dijkstra where path cost is a max, not a sum.arrow_forward
- 4Min Cost to Connect All Points (LeetCode 1584)MediumConnect all points with minimum total Manhattan distance: it's a minimum spanning tree, built with Prim's.arrow_forward
- 5Find the City With the Smallest Number of Neighbors (LeetCode 1334)MediumPick the city reaching the fewest others within a distance limit: all-pairs shortest paths, then count.arrow_forward
- 6Path with Maximum Probability (LeetCode 1514)MediumMost likely path between two nodes: Dijkstra with a max-heap, multiplying probabilities, not adding.arrow_forward
- 7Alien Dictionary (LeetCode 269)HardRecover an alien alphabet from sorted words: compare neighbours for letter rules, then topologically sort.arrow_forward
- 8Reconstruct Itinerary (LeetCode 332)HardUse every ticket once from JFK, smallest lexical order: an Eulerian path via Hierholzer's algorithm.arrow_forward
- 9Swim in Rising Water (LeetCode 778)HardEarliest time to swim corner to corner as water rises: minimise the highest cell on the path with a heap.arrow_forward
- 10Critical Connections in a Network (LeetCode 1192)HardFind connections whose removal splits the network: bridges, found with Tarjan's disc/low DFS in one pass.arrow_forward