← Questions

Best-scoring ski run through a trail map

0
AirbnbCodingLast asked Mar 2026

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 from from to to with a non-negative integer cost.
  • checkpoints[j] = [name, reward] gives the reward for arriving at name. A checkpoint that is not listed has reward 0.
  • Return the highest net score over all runs from START to any END_ checkpoint. The answer may be negative. Return None if no finish can be reached from START.

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 START itself be a finish?
  • Do checkpoints that appear only in checkpoints, and not in routes, 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 START topologically 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 from START.
  • Returns the best score over END_ nodes, or None. 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 k runs.

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

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding