The Path with Maximum Probability problem gives you a graph with probabilistic edge weights (values between 0 and 1). Find the path from start to end that maximizes the probability of success (product of edge probabilities). This coding problem applies Dijkstra-style traversal where you maximize the product instead of minimizing the sum. The shortest path, array, graph, and heap interview pattern is the core.
Samsung, Microsoft, Meta, Amazon, and Google ask this because it tests whether candidates can generalize shortest path algorithms to different objective functions. Maximizing probability products is analogous to minimizing sum distances — the key is using a max-heap and the correct update condition.
Modified Dijkstra with max-heap. Initialize prob[start]=1.0, all others=0.0. Use a max-heap of (probability, node). For each node processed: for each neighbor with edge probability p, new_prob = current_prob * p. If new_prob > prob[neighbor], update and push to heap. Return prob[end] when end is processed (or 0 if not reachable).
Nodes=[0,1,2]. Edges: 0-1(0.5), 1-2(0.5), 0-2(0.2). Start=0, End=2.
Probability path problems are multiplication-based Dijkstra variants. Key transformation: "maximize product" ↔ "minimize negative log" — so you can convert to standard Dijkstra if needed, but a max-heap with probability is more intuitive. Practice adapting Dijkstra to different objective functions: sum, product, max, min. The algorithm structure is the same; only the priority and update condition change.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Cost of a Path With Special Roads | Medium | Solve | |
| Minimum Cost to Buy Apples | Medium | Solve | |
| Find Minimum Time to Reach Last Room II | Medium | Solve | |
| Find Minimum Time to Reach Last Room I | Medium | Solve | |
| Minimum Cost Path with Edge Reversals | Medium | Solve |