Problem · Graph
Minimum Score of a Path Between Cities
Learn this problemProblem statement
You are given n cities numbered from 1 through n and an array roads. Each roads[i] = [a, b, distance] describes a bidirectional road between cities a and b.
The score of a path is the minimum road distance used anywhere along that path. Cities and roads may be visited more than once.
Return the minimum possible score of a path from city 1 to city n. At least one such path exists.
Function
minScore(n: int, roads: int[][]) → intExamples
Example 1
n = 4roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]return = 5The path 1 -> 2 -> 4 has score min(9, 5) = 5, which is optimal.
Example 2
n = 4roads = [[1,2,2],[1,3,4],[3,4,7]]return = 2Because revisits are allowed, a walk can use the road of length 2 before continuing to city 4.
More Visa problems
- Minimum Cost to Attend Required CoursesOA · Seen Jul 2026
- Planning ProductionOA · Seen Jul 2026
- Subarray SumOA · Seen Jul 2026
- Maximum Even Tag SumOA · Seen Jun 2026
- Transform Binary MatrixOA · Seen Jun 2026
- Minimum Cost to Select People for Skill QuotasOA · Seen May 2026
- Longest Selectable Non-Decreasing SubarrayOA · Seen Apr 2026
- Maximize Capped Contribution SumOA · Seen Apr 2026