Problem · Graph
Minimize Path Value
Learn this problemProblem statement
You are given a weighted undirected graph with graph_nodes nodes numbered from 1 through graph_nodes. The arrays graph_from, graph_to, and graph_weight describe the graph's edges: edge i connects graph_from[i] and graph_to[i] with weight graph_weight[i].
The stress level of a path is the maximum edge weight on that path.
Return the minimum possible stress level among all paths from source to destination. If no such path exists, return -1. If source = destination, return 0.
Although the endpoint arrays are named graph_from and graph_to, every edge is undirected.
Function
leastStressfulPath(graph_nodes: int, graph_from: int[], graph_to: int[], graph_weight: int[], source: int, destination: int) → intExamples
Example 1
graph_nodes = 4graph_from = [2,2,1,4]graph_to = [1,3,4,3]graph_weight = [100,200,10,20]source = 1destination = 3return = 20The graph is:
(2)
/ \
100 200
/ \
(1) (3)
\ /
10 20
\ /
(4)- The path
1 -> 2 -> 3has stressmax(100, 200) = 200. - The path
1 -> 4 -> 3has stressmax(10, 20) = 20.
The minimum possible stress is 20.
Constraints
1 <= graph_nodes <= 10^5.1 <= graph_from.length = graph_to.length = graph_weight.length <= 10^5.1 <= graph_from[i], graph_to[i], source, destination <= graph_nodes.0 <= graph_weight[i] <= 10^9.
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026