FastPrepMinimum Score of a Path Between Cities
Problems/Minimum Score of a Path Between Cities

Minimum Score of a Path Between Cities

Visa logoVisa● MediumOA
QuestionFunctionExamples

Problem statement

Source note: The interview report identifies the task through its exact canonical problem link. The judged core task matches that source at about 99%.

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[][]) → int

Examples

Example 1

n = 4roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]return = 5

The 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 = 2

Because revisits are allowed, a walk can use the road of length 2 before continuing to city 4.

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int minScore(int n, int[][] roads) {
      // write your code here
    }
}
Checking account…