Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Boss fightThe Ticket Trail

Learn
Play
Prove
Problem context and objectives
Mission briefing

Realm network architect · Routes have costs, dependencies, and unreliable bridges

Choose the next frontier that preserves the route guarantee: The Ticket Trail.

One locally tempting edge can invalidate the whole journey.

How you win

  1. 1Recognize when Hierholzer Eulerian itinerary matches the clues
  2. 2Keep this true after every move: every removed ticket appears exactly once in the reversed postorder route
  3. 3Reach the result within O(E log E)

Rules and pressure

  • Target cost: O(E log E)
  • State rule: every removed ticket appears exactly once in the reversed postorder route
Lesson 1 of 3

Live algorithm trace

Hierholzer Eulerian itinerary

Complete execution
1 of 6
JFK
start
ATL
JFK
SFO
ATL
SFO

Store each departure's destinations so popping chooses the lexical minimum.

1store destinations in reverse lexical order
2dfs(airport)
3while an outgoing ticket remains
4remove the smallest destination and recurse
5append airport after exhausting edges
6reverse the postorder route
JFK = SFO,ATLATL = SFO,JFKSFO = ATL
Truth to preserve / Cost target
Truth to preserve

every removed ticket appears exactly once in the reversed postorder route

Cost target

O(E log E)

Always consume the lexicographically smallest outgoing ticket, but append an airport only after it has no tickets left. Reversing this postorder trail splices cycles into one Eulerian path.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead