Best-scoring ski run through a trail map
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Airbnb's coding round, last asked Mar 2026. It tests graphs, dag and dynamic programming.
A ski area has mapped its one-way trails between named checkpoints. The trail map has no cycles: once you ski down a trail you can never get back to where you were.
Every trail has a cost to ski it, and some checkpoints award points when you arrive. The skier starts at the checkpoint START and may finish at any checkpoint whose name begins with END_.
The net score of a run is the sum of the rewards of every checkpoint on it (including START and the finish) minus the sum of the costs of the trails it uses.
Implement:
def max_net_score(routes: list[list], checkpoints: list[list]) -> int | None
-
routes[i] = [from, cost, to]is a one-way trail fromfromtotowith a non-negative integercost. -
checkpoints[j] = [name, reward]gives the reward for arriving atname. A checkpoint that is not listed has reward 0. - Return the highest net score over all runs from
STARTto anyEND_checkpoint. The answer may be negative. ReturnNoneif no finish can be reached fromSTART.
Constraints
- Up to 10^5 checkpoints and 2 * 10^5 trails.
- The graph is a DAG. There may be more than one trail between the same two checkpoints.
- Rewards fit in a 32-bit integer.
Example 1
routes = [["START", 3, "A"], ["START", 1, "B"], ["A", 2, "END_1"],
["B", 4, "C"], ["C", 1, "END_1"], ["C", 6, "END_2"]]
checkpoints = [["A", 8], ["B", 2], ["C", 9], ["END_1", 5], ["END_2", 14]]
Output: 14. The run START -> B -> C -> END_2 scores -1 + 2 - 4 + 9 - 6 + 14 = 14. The other runs score 8 (START -> A -> END_1) and 10 (START -> B -> C -> END_1).
Example 2
routes = [["START", 5, "END_X"]]
checkpoints = [["END_X", 2]]
Output: -3. The only run costs more than it earns, but it is still the best run.
Be ready to return the route itself, and to discuss what changes if each trail also takes time and the skier has a time limit.
Clarifying questions
- Can a run pass through an
END_checkpoint and keep going to a later finish? - Can
STARTitself be a finish? - Do checkpoints that appear only in
checkpoints, and not inroutes, matter? - If two trails join the same checkpoints, should we take the cheaper one?
What a strong answer covers
- Treats it as a longest path in a DAG, with rewards on nodes and costs on edges.
- Orders the checkpoints reachable from
STARTtopologically with Kahn's algorithm, then relaxes each trail once:score[to] = max(score[to], score[from] - cost + reward[to]). - Starts with
score[START] = reward[START], and ignores nodes that cannot be reached fromSTART. - Returns the best score over
END_nodes, orNone. That is O(V + E). - Explains why Dijkstra does not apply (maximizing, with mixed signs), and why the DAG makes this easy.
- Tests both examples, parallel trails, an unreachable finish, and a negative best.
Follow-ups
- Return the route.
- Each trail also takes time, and the run has a time limit.
- The map may contain cycles.
- List the top
kruns.
Where it's asked
- Airbnb · Coding · Last asked Mar 202645 min · Live coding, one or two rounds, from the same pool as the screen
What it tests
graphs · dag · dynamic programming · topological sort
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
