Trains the technique from
LeetCode 1976Number of Ways to Arrive at DestinationThis 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 city has n junctions numbered 0 through n - 1, joined by two-way lanes. lanes[i] = [a, b, minutes] means a lane runs between junction a and junction b and takes minutes to ride in either direction.
At most one lane joins any pair of junctions, and every junction can be reached from every other one.
A courier sets off from junction 0 bound for junction n - 1 and will only ride a route whose total time is the smallest possible. Report how many such routes there are, reduced modulo 10^9 + 7 because the tally outgrows any fixed-width integer.
Example 1
The single lane straight to junction 3 takes 5 minutes. Hopping through junction 1 takes 2 minutes and so does hopping through junction 2, and those two are the only quickest routes.
Example 2
One lane joins the two junctions and it can be ridden either way, so there is a single route.
Example 3
Three minutes is the least possible: the direct lane, the chain through junctions 1 and 2, and the chain through junctions 3 and 4.
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 count_paths(n: int, lanes: list[list[int]]) -> int:public int countPaths(int n, int[][] lanes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.