← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round with a graph/shortest-path problem. Pretty standard setup but the round-trip twist made it less obvious than it first looked.

Questions Asked (1)

Q1

Given a list of flights with source, destination, and price, find the minimum cost of a round-trip starting and ending at city A.

Algorithms & Data Structures
Author's notes

My first instinct was just Dijkstra from A and call it a day.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the flights as a directed weighted graph where cities are nodes and flights are edges with prices as weights. The problem reduces to finding the shortest cycle through city A, which can be solved by running Dijkstra from A to all nodes, then from all nodes to A on the reversed graph, and taking the minimum sum of distances for any node B (where B ≠ A).

Pro tip: Clarify whether the round-trip must use distinct outbound and return flights (i.e., no reusing the same flight) and whether multiple flights between the same cities are allowed. This shows attention to edge cases and prevents incorrect assumptions.

1. Clarify requirements and constraints

Ask about graph properties: directed/undirected, positive weights, possible multiple edges, and whether the trip must consist of two distinct flights. Confirm that the goal is to minimize total cost.

2. Model as a graph problem

Represent cities as nodes and flights as directed edges with weights equal to prices. The round-trip is a cycle that starts and ends at A, possibly visiting other cities.

3. Choose an algorithm

Use Dijkstra's algorithm to compute shortest paths from A to all nodes, and from all nodes to A by running Dijkstra on the reversed graph. Alternatively, consider Floyd-Warshall if the graph is small.

4. Compute the minimum round-trip cost

For each city B ≠ A, sum the shortest distance from A to B and from B to A. The minimum over all B is the answer. If no such B exists, return -1 or indicate impossibility.

5. Analyze complexity and edge cases

Discuss time complexity (O(E log V) with Dijkstra) and handle edge cases: no path, direct round-trip A→B→A, and potential negative weights (though prices are positive).

Key Points to Mention

  • Graph representation: adjacency list for efficiency
  • Dijkstra's algorithm for shortest paths with non-negative weights
  • Reversing the graph to compute shortest paths to A
  • Time complexity: O(E log V) with binary heap
  • Handling disconnected graphs and returning -1 if no round-trip exists
  • Potential optimization: early termination if the minimum sum exceeds current best

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