Highest Product of Edge Success Probabilities

Quick Overview

Highest Product of Edge Success Probabilities. The graph has n nodes0..n-1 and undirected edges with success probabilities succProb.

Highest Product of Edge Success Probabilities

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The graph has n nodes 0..n-1 and undirected edges with success probabilities succProb. A path's success probability is the product of its edge probabilities. Return the largest product from start_node to end_node,or 0 if no path exists. The source accepts absolute error at most 0.00001. ```cpp class Solution { public: double maxProbability(int n, vector<vector<int>>& edges, vector<double>& succProb, int start_node, int end_node); }; ``` ### Examples **Example 1:** ```text Input: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.8,0.5,0.3], start_node = 0, end_node = 2 Output: 0.4 Explanation: The two-edge path has product0.8*0.5=0.4,better than0.3. ``` **Example 2:** ```text Input: n = 2, edges = [], succProb = [], start_node = 0, end_node = 1 Output: 0.0 Explanation: The destination is disconnected. ``` ### Constraints - `2 <= n <= 10000`; start_node and end_node are different labels in `[0,n-1]`. - edges and succProb have the same length 0 to 20000. - Each edge joins different valid node labels,and at most one edge joins any unordered pair. - `0 <= succProb[i] <= 1`. - Absolute answer error at most 10^-5 is accepted. ### Contract considerations The original prose uses start/end while the exact native parameter names are start_node/end_node; these denote the same endpoints. ```hint Read the boundary condition Check disconnected endpoints and edge probabilities at both zero and one. Preserve the undirected-edge interpretation and stated numeric tolerance. ``` ### Boundary reminders The original prose uses start/end while the exact native parameter names are start_node/end_node; these denote the same endpoints.

Overview: Highest Product of Edge Success Probabilities. The graph has n nodes0..n-1 and undirected edges with success probabilities succProb.

Google logo
Google
Jun 7, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The graph has n nodes 0..n-1 and undirected edges with success probabilities succProb. A path's success probability is the product of its edge probabilities. Return the largest product from start_node to end_node,or 0 if no path exists. The source accepts absolute error at most 0.00001.

class Solution {
public:
    double maxProbability(int n, vector<vector<int>>& edges, vector<double>& succProb, int start_node, int end_node);
};

Examples

Example 1:

Input: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.8,0.5,0.3], start_node = 0, end_node = 2
Output: 0.4
Explanation: The two-edge path has product0.8*0.5=0.4,better than0.3.

Example 2:

Input: n = 2, edges = [], succProb = [], start_node = 0, end_node = 1
Output: 0.0
Explanation: The destination is disconnected.

Constraints

  • 2 <= n <= 10000 ; start_node and end_node are different labels in [0,n-1] .
  • edges and succProb have the same length 0 to 20000.
  • Each edge joins different valid node labels,and at most one edge joins any unordered pair.
  • 0 <= succProb[i] <= 1 .
  • Absolute answer error at most 10^-5 is accepted.

Contract considerations

The original prose uses start/end while the exact native parameter names are start_node/end_node; these denote the same endpoints.

Boundary reminders

The original prose uses start/end while the exact native parameter names are start_node/end_node; these denote the same endpoints.