FastPrepReconstruct Itinerary
Problems/Reconstruct Itinerary

Reconstruct Itinerary

PhonePe logoPhonePe● HardONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real PhonePe onsite interview report. The report linked the exact Reconstruct Itinerary task, but it did not reproduce the rules, function interface, examples, or constraints. The core task match is about 95%.

You are given airline tickets represented as [from, to] pairs. Reconstruct the itinerary that uses every ticket exactly once.

The itinerary must start at "JFK". If multiple valid itineraries exist, return the lexicographically smallest itinerary when read as a single sequence of airport codes.

Function

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

Examples

Example 1

tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]return = ["JFK","MUC","LHR","SFO","SJC"]

There is only one route that uses all tickets from JFK.

Example 2

tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]return = ["JFK","ATL","JFK","SFO","ATL","SFO"]

Both choices from JFK can lead to valid routes, but the route beginning with ATL is lexicographically smaller.

Constraints

  • 1 <= tickets.length <= 300.
  • tickets[i].length == 2.
  • Each airport code has 1 to 3 uppercase English letters.
  • The departure and arrival on a ticket differ.
  • A complete itinerary that starts at "JFK" and uses every ticket always exists.

More PhonePe problems

  • Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
  • K-th Smallest Value in a Sorted MatrixONSITE INTERVIEW · Seen Oct 2026
  • Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
All PhonePe interview questionsSee PhonePe hiring insights
Saved
class Solution {
    public List<String> findItinerary(List<List<String>> tickets) {
      // write your code here
    }
}
Checking account…