← Uber Interview Insights

Uber·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Uber frontend interview that threw a classic graph problem at me, which I was not expecting for a frontend role. Pretty standard technical phone screen vibe.

Questions Asked (1)

Q1

Given a list of flights with source, destination, and cost, find the cheapest route between two cities using at most k stops. Return -1 if no route exists.

Algorithms & Data Structures
Author's notes

Wasn't ready for a graph question in a frontend screen, so I froze for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the flights as a weighted directed graph and use a modified BFS (level-by-level) or Bellman-Ford to find the cheapest path with at most k stops. Since k is small, an iterative relaxation approach (Bellman-Ford) is efficient and easy to reason about. Alternatively, use Dijkstra with a state of (city, stops) but be careful with the stop constraint.

Pro tip: Clarify whether 'at most k stops' means the number of intermediate cities (stops) or the number of flights (edges). This off-by-one detail is a common pitfall; confirming it upfront shows attention to detail and avoids wasted effort.

1. Clarify the problem

Confirm the definition of 'stops' (intermediate cities vs. flights), whether costs are positive, and if multiple routes between same cities exist. Also ask about input size to choose the right algorithm.

2. Model as a graph

Represent cities as nodes and flights as directed edges with weights (cost). This abstraction helps in applying standard graph algorithms.

3. Choose an algorithm

For small k, use Bellman-Ford with at most k+1 iterations (since k stops means k+1 edges). Alternatively, use BFS with level tracking and keep track of minimum cost to each city at each stop count.

4. Implement and handle edge cases

Initialize distances to infinity, set source distance to 0. Iterate k+1 times, relaxing all edges. After iterations, return distance to destination or -1 if unreachable. Handle cases like source equals destination (cost 0) and no flights.

5. Analyze complexity and optimize

Time complexity: O(k * E) for Bellman-Ford, where E is number of flights. Space: O(V). Mention that for large k, Dijkstra with state might be better, but for small k, this is optimal.

Key Points to Mention

  • Graph representation: adjacency list or edge list
  • Bellman-Ford algorithm and its iterative relaxation
  • BFS with level tracking (stops) and distance array
  • Handling the 'at most k stops' constraint correctly (k+1 edges)
  • Time and space complexity analysis
  • Edge cases: no route, source equals destination, negative cycles (if costs can be negative)

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