Skip to main content
LeetCode 1514, Medium. Topics: Array, Graph Theory, Heap (Priority Queue), Shortest Path, Dijkstra’s Algorithm. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a<sub>i</sub>, b<sub>i</sub>] is an undirected edge connecting the nodes a<sub>i</sub> and b<sub>i</sub> with a probability of success of traversing that edge succProb[i]. Given two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability. If there is no path from start to end, return 0. Your answer will be accepted if it differs from the correct answer by at most 10<sup>-5</sup>.

Examples

Example 1
Example 2
Example 3

Constraints

  • 2 <= n <= 10^4
  • 0 <= start, end < n
  • start != end
  • 0 <= a<sub>i</sub>, b<sub>i</sub> < n
  • a<sub>i</sub> != b<sub>i</sub>
  • 0 <= succProb.length == edges.length <= 2 * 10^4
  • 0 <= succProb[i] <= 1
  • There is at most one edge between every two nodes.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026