35/40
Part 7 of 7 · Follow-upsLearn and do

How many routes share the best score? Keep a count next to each total

A stretch that beats a junction's total replaces its count. One that ties it adds to it:

if best[j] + score > best[lower]:
    # a better total: start the count over
    best[lower], ways[lower] = best[j] + score, ways[j]
elif best[j] + score == best[lower]:
    # a tie: add the routes
    ways[lower] += ways[j]
Predict

Forget scores and count every route from top to an exit in PARK. How many are there?

Pick an answer above to see the rest