Leetcode Problem 1514. Path with Maximum Probability
1514. Path with Maximum Probability
Leetcode Solutions
Dijkstra's Algorithm for Maximum Probability Path
Create a graph representation from the edges and probabilities.
Initialize a max-heap priority queue and an array to store the maximum probability to each node from the start node.
Set the probability of the start node to 1 and all others to 0.
Add the start node to the priority queue.
While the priority queue is not empty:
a. Pop the node with the highest probability.
b. If this node is the end node, break the loop.
c. For each neighbor, calculate the new probability by multiplying the current node's probability with the edge probability.
d. If the new probability is higher than the neighbor's current probability, update it and add the neighbor to the priority queue.
Return the maximum probability for the end node.
Bellman-Ford Algorithm for Maximum Probability Path