FastPrepPath With Maximum Probability
Problems/Path With Maximum Probability

Path With Maximum Probability

Salesforce logoSalesforce● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Salesforce onsite interview. The report names Path With Maximum Probability and describes walking through a graph. It does not give the exact graph format, the function signature or the limits. Our version is about 92% the same as the reported question.

You are given an undirected graph with n nodes numbered from 0 through n - 1. Edge edges[i] connects two nodes and succeeds with probability probabilities[i].

The probability of a path is the product of the probabilities of its edges. Return the maximum probability of reaching end from start.

  • If no path exists, return 0.0.
  • If start == end, return 1.0.

Function

maxProbability(n: int, edges: int[][], probabilities: double[], start: int, end: int) → double

Examples

Example 1

n = 3edges = [[0,1],[1,2],[0,2]]probabilities = [0.5,0.5,0.2]start = 0end = 2return = 0.25

The path 0 -> 1 -> 2 has probability 0.5 * 0.5 = 0.25, which is greater than the direct edge probability 0.2.

Example 2

n = 3edges = [[0,1],[1,2],[0,2]]probabilities = [0.5,0.5,0.3]start = 0end = 2return = 0.3

The direct edge from 0 to 2 succeeds with probability 0.3, exceeding the two-edge path probability 0.25.

Example 3

n = 3edges = [[0,1]]probabilities = [0.5]start = 0end = 2return = 0.0

Node 2 is unreachable from node 0.

Constraints

  • 1 <= n <= 10^4
  • 0 <= edges.length = probabilities.length <= 2 * 10^4
  • Each edge contains two distinct valid node indices.
  • 0.0 <= probabilities[i] <= 1.0
  • 0 <= start, end < n
  • Parallel edges are allowed.

More Salesforce Onsite Interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
  • Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Product Path in a Directed GraphGoogle · ONSITE INTERVIEWGoogle interview questions
  • Dijkstra's Shortest PathsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Single-Source Shortest PathsRippling · ONSITE INTERVIEWRippling interview questions
  • Minimum-Weight Path Through a MatrixMeta · ONSITE INTERVIEWMeta interview questions
  • Hub Vertices Within a RadiusThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Minimum Path Cost with Edge DiscountsSkyscanner · ONSITE INTERVIEWSkyscanner interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
  • Dijkstra Shortest Paths in a Weighted Undirected GraphGoldman Sachs · PHONE SCREENGoldman Sachs interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public double maxProbability(int n, int[][] edges, double[] probabilities, int start, int end) {
        // write your code here
    }
}
Checking account…