1/40
Learn

The best way down a trail park, the way the coding round asks

An Airbnb software engineer candidate reported a coding round about skiing from the top of a mountain to one of several finish checkpoints, and finding the best-scoring way down (1 report). Minimum Cost to Reach Destination in Time, on an Airbnb LeetCode tag list (1 source), has the shape of the last level: one more number in the state. This lesson's practice problem puts it in a downhill bike park, in three levels:

  1. best_score(stretches, start, exits): the highest total of a route from the trailhead to any exit. Each stretch of trail has a score, and some scores are negative.
  2. best_route(stretches, start, exits): the route itself, and when routes tie, the one whose list of junctions comes first.
  3. best_score_limited(stretches, start, exits, expert, limit): the best total of a route that rides at most limit expert stretches.
On a park of 13 stretches, from top to the exits gate and lotReturns
best_score15, riding past the exit at gate and on to lot
best_route["top", "pines", "bowl", "gate", "lot"]
best_score_limited, two stretches expert-only, a limit of 113
the same, with a limit of 012

Every stretch runs downhill, so the park has no loops, and one test is 50,000 junctions in a row. The lesson builds up to it: the four things to write before any code, two states for each position, a table over two strings, the best route through a graph with no cycles, the answer itself, and a count in the state. 17 steps end with a small task in the editor.