Trains the technique from
LeetCode 1514Path with Maximum ProbabilityThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A courier company runs n depots, numbered 0 to n - 1, joined by two-way trunk links.
The links are given as two parallel arrays. links[i] = [u, v] is a link that a parcel may cross in either direction, and success[i] is the probability that a parcel crossing that link arrives undamaged. No pair of depots is joined by more than one link, and no link joins a depot to itself.
A route is a sequence of links leading from one depot to the next. A parcel survives the route only if it survives every link on it, and the links fail independently, so the route's success probability is the product of the success values of the links it uses.
Return the largest success probability of any route from depot origin to depot target. If no route joins them at all, return 0.0.
Report the probability as a decimal number; an answer within 1e-5 of the correct value is accepted.
Example 1
The route 0 to 1 to 3 uses the links with chances 0.5 and 0.75, so a parcel survives it with probability 0.5 * 0.75 = 0.375. The other route, 0 to 2 to 3, multiplies out to 0.875 * 0.25 = 0.21875.
Example 2
Depots 0, 1 and 2 sit on one side and depots 3 and 4 on the other, with no link crossing between the two sides, so no route reaches depot 4 from depot 0.
Example 3
The single link is written as [0,1] but may be crossed in either direction, so the one-link route from depot 1 to depot 0 carries its chance of 0.625.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_delivery_odds(n: int, links: list[list[int]], success: list[float], origin: int, target: int) -> float:public double bestDeliveryOdds(int n, int[][] links, double[] success, int origin, int target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.