← Meta Interview Insights

Meta·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

Meta ML Engineer interview with a graph problem that sounds straightforward until you realize they want a specific algorithm by name. One question, but it had layers.

Questions Asked (1)

Q1

Given a list of airline tickets as [departure, arrival] pairs, reconstruct the full itinerary starting from JFK using all tickets exactly once. If multiple valid itineraries exist, return the one that comes first in lexical order.

Algorithms & Data Structures
Author's notes

I knew this was an Eulerian path problem pretty quickly, which felt good.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the tickets as a directed graph and use Hierholzer's algorithm to find an Eulerian path starting from JFK. To ensure the lexicographically smallest itinerary, sort each airport's destinations in reverse order and use a stack-based DFS, building the itinerary in reverse.

Pro tip: Emphasize that sorting destinations in reverse order and using a stack naturally yields the correct lexical order without extra sorting of the final path. Also, mention that this approach handles edge cases like multiple valid paths and disconnected components.

1. Understand the problem

Recognize that this is finding an Eulerian path in a directed graph where each ticket is an edge. The path must start at JFK and use all edges exactly once.

2. Choose the algorithm

Use Hierholzer's algorithm for Eulerian path. It efficiently finds a path by following edges until stuck, then backtracking.

3. Handle lexical order

Sort each airport's destination list in reverse lexical order. Use a stack (or recursion) to explore, ensuring the smallest lexical path is built.

4. Implement and test

Build the graph, run DFS, and collect the itinerary in reverse. Test with edge cases like multiple valid paths and cycles.

Key Points to Mention

  • Eulerian path concept and conditions
  • Hierholzer's algorithm and its efficiency
  • Using a stack for iterative DFS to avoid recursion limits
  • Sorting destinations in reverse order for lexical order
  • Time and space complexity: O(E log E) due to sorting, O(E) space
  • Handling edge cases: multiple tickets from same airport, cycles, disconnected graph

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.