FastPrepReconstruct Itinerary
Problems/Reconstruct Itinerary

Reconstruct Itinerary

Tripjack logoTripjack● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This comes from an in-person Tripjack interview for a backend role. Its first round had two coding questions, and this was one of them. The report only links to Reconstruct Itinerary by name.

The report gives no limits or examples, so this version uses the usual rules: start at JFK, use every ticket once, and return the smallest trip in lexical order. There are up to 300 tickets.

Our version is about 95% the same as the reported question.

You are given a list of airline tickets. Each ticket tickets[i] = [from, to] is one flight from airport from to airport to. All the tickets belong to one traveler, who starts at "JFK".

Put the trip back together: start at "JFK" and use every ticket exactly once. Return the airports in the order the traveler visits them.

If more than one trip works, return the smallest one in lexical order. To compare two trips, read them airport by airport. At the first airport where they differ, the trip whose airport code comes first alphabetically is smaller.

The same flight can appear on more than one ticket. Each copy is a separate ticket that must be used.

Function

findItinerary(tickets: List<List<String>>) → List<String>

Examples

Example 1

tickets = [["DEL","BOM"],["JFK","DEL"],["BOM","SFO"]]return = ["JFK","DEL","BOM","SFO"]

The trip starts at JFK. The only ticket from JFK goes to DEL, the only ticket from DEL goes to BOM, and the only ticket from BOM goes to SFO. That uses all three tickets.

Example 2

tickets = [["JFK","KUL"],["JFK","NRT"],["NRT","JFK"]]return = ["JFK","NRT","JFK","KUL"]

From JFK the traveler can fly to KUL or to NRT. There is no ticket out of KUL, so flying there first would leave the other two tickets unused.

So the trip goes JFK to NRT, back to JFK, and then to KUL.

Example 3

tickets = [["JFK","BLR"],["BLR","JFK"],["JFK","HYD"],["HYD","BLR"]]return = ["JFK","BLR","JFK","HYD","BLR"]

Two trips use every ticket: JFK, BLR, JFK, HYD, BLR and JFK, HYD, BLR, JFK, BLR.

They first differ at the second airport. BLR comes before HYD alphabetically, so the first trip is the answer.

Constraints

  • 1 <= tickets.length <= 300
  • tickets[i].length == 2
  • tickets[i][j].length == 3
  • Each airport code is made of uppercase English letters.
  • tickets[i][0] != tickets[i][1]
  • The tickets always allow at least one trip that starts at "JFK" and uses every ticket.

More Tripjack Onsite Interview questions

  • Wildcard MatchingONSITE INTERVIEW · Seen Nov 2026
  • Jump Game IIONSITE INTERVIEW · Seen Aug 2026
  • Number of IslandsONSITE INTERVIEW · Seen Aug 2026
  • Zigzag ConversionONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Top-Rated Similar MoviesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
  • Create Lexicographically Largest PermutationOracle · OAOracle interview questions
  • Deterministic Depth-First Graph TraversalWaymo · PHONE SCREENWaymo interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Priority Graph: First Arrival TimesIntuit · OAIntuit interview questions
  • Traverse an Up-Down-Right Pointer StructureBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Largest Island After One Land ConversionAmazon · ONSITE INTERVIEW
  • Reconstruct an Itinerary Without a Fixed StartPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
All Tripjack interview questionsSee Tripjack hiring insights
Saved
class Solution {
    public List<String> findItinerary(List<List<String>> tickets) {
        // Write your code here.
    }
}
Checking account…