Path with Maximum Probability
Given an undirected weighted graph of n nodes where edge i connects edges[i][0] and edges[i][1] with success probability succProb[i], return the maximum probability of a path from start_node to end_node (the product of the edge probabilities along the path). If no path exists, return 0.
Open official problem prompt ↗Compute the single most reliable route from start to end, measured as the product of edge success probabilities.
Each edge is a relay that forwards a signal with some success chance; you want the chain of relays that gives the signal its best overall chance of arriving intact.
- Input
- n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start_node = 0, end_node = 2
- Output
- 0.25
- Why
- Path 0->1->2 gives 0.5 * 0.5 = 0.25, which beats the direct edge 0->2 with probability 0.2.
2 <= n <= 10^40 <= edges.length <= 2*10^4edges[i].length == 20 <= a, b < n, a != bsuccProb.length == edges.length0 <= succProb[i] <= 1There is at most one edge between every two nodes