27 · Shortest Paths

#1514 Path with Maximum Probability

Mediumsolve on LeetCode ↗

frequently reported atGoogle

the problem

In plain words

An undirected graph has n nodes. edges[i] = [a, b] succeeds with probability succProb[i]. Return the highest success probability of any path from start to end, or 0 if there is no path.

in n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2

out 0.25

0→1→2 = 0.5 × 0.5 = 0.25 beats 0→2 = 0.2.

in n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2

out 0.0

  • 2 ≤ n ≤ 10⁴
  • 0 ≤ edges.length ≤ 2·10⁴
  • 0 ≤ succProb[i] ≤ 1
  • At most one edge between two nodes

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #743
      Network Delay Time
      Mediumin Shortest Paths
    2. #1631
      Path With Minimum Effort
      Mediumin Shortest Paths