← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a graph/BFS problem that's a twist on the classic knight moves puzzle. Pretty standard technical screen but the bounded board constraint is what separates the people who actually think it through from the people who just recite the infinite-board solution.

Questions Asked (1)

Q1

Given an N×N chessboard with a knight at a starting square, find the minimum number of moves to reach a target square. The knight cannot leave the board. Return -1 if the target is unreachable.

Algorithms & Data Structures
Author's notes

My first instinct was BFS and that's correct, but I almost forgot to handle the boundary check inside the neighbor generation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the chessboard as a graph where each square is a node and knight moves are edges, then use BFS to find the shortest path from start to target. BFS guarantees the minimum number of moves because all edges have equal weight. If the target is never reached, return -1.

Pro tip: Mention that BFS is optimal here because it explores level by level, and discuss how to optimize using bidirectional BFS or A* with a heuristic like Chebyshev distance for large boards. Also, handle edge cases like start equals target (return 0) and unreachable squares (e.g., on a 1x1 board).

1. Clarify the problem

Confirm the board size N, the starting and target coordinates, and that the knight moves in standard L-shapes (2,1) or (1,2). Ask about constraints like N up to 10^5 or if multiple queries are expected.

2. Choose the algorithm

Select BFS for unweighted shortest path. Explain that BFS explores all squares reachable in k moves before k+1 moves, ensuring the first time we reach the target is the minimum.

3. Implement BFS

Use a queue to store squares and a distance array or hash map to track visited squares and their distances. For each square, generate up to 8 valid knight moves within the board.

4. Handle edge cases

If start equals target, return 0. If the queue empties without reaching the target, return -1. Also consider N=1 (no moves possible) and N=2 (knight cannot move).

5. Analyze complexity and optimize

Time complexity is O(N^2) since each square is visited once, and space is O(N^2) for the visited set. For large N or multiple queries, discuss bidirectional BFS or precomputing distances.

Key Points to Mention

  • Graph modeling: squares as nodes, knight moves as edges
  • BFS guarantees shortest path in unweighted graphs
  • Time and space complexity: O(N^2)
  • Edge cases: start equals target, unreachable target, small boards
  • Optimization techniques: bidirectional BFS, A* with heuristic
  • Handling multiple queries: precompute all-pairs shortest paths or use BFS from each start

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