ludus

Cheapest Flights

ld-0012 · 8 › ████████░░ · graphs, algorithms · requires: arrays, lambda, algorithmic · oner generalized golfed

You and a few friends are planning a holiday and want to spend as little money on flights as possible. You've gathered data on every flight available: where it departs, where it lands, and what it costs. Flights are one-way — a listed flight cannot be flown in reverse. The same pair of airports may be listed more than once at different prices.

Given the source and destination airports, produce the cheapest possible route as a list of airports in visiting order, one per row, starting with the source and ending with the destination. There is always exactly one cheapest route.

Work on it

  1. Make a copy of the template — it becomes your private sheet.
  2. Solve it however you like — helper columns and extra tabs are fair game. The one rule: the grader swaps INPUT for other datasets, so never put your own content inside INPUT.
  3. Check yourself against the expected sample output shown in your copy (and below).
  4. Submit below — Share → "anyone with the link, Viewer", paste the link. Your sheet is graded against 3 hidden datasets, so hardcoded answers won't survive.

Sample

Input (Input!B2:F22)

FromToCostSource
HNDSFO450HND
HNDSEA400Destination
HNDJFK1400JFK
SFODEN200
SEADEN300
SFOORD500
DENORD150
ORDJFK180
DENJFK400
SEAJFK900

Expected output (Answer!B3:B22)

Route
HND
SFO
DEN
ORD
JFK

Adapted from "Cheapest Flights" in the astral.cafe Community Practice Problems sheet.