← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Two coding problems for an Uber SWE round. The first was a grid traversal thing, the second was a tree path palindrome counter. Both had enough edge cases to keep you honest.

Questions Asked (2)

Q1

Given a 2D grid with empty cells and obstacles, find all positions where a robot's directional distances to the nearest obstacle in each of the four directions exactly match a given target signature. If any direction has no obstacle before the grid boundary, that position is invalid.

Algorithms & Data Structures
Author's notes

The boundary condition tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Precompute the distance to the nearest obstacle in each of the four directions for every cell using four directional passes (left, right, up, down). Then iterate through all cells and check if the tuple of distances matches the target signature, ensuring no direction has an infinite distance (i.e., no obstacle before the boundary).

Pro tip: Clarify upfront that the robot's position must have obstacles in all four directions; if any direction lacks an obstacle, the cell is automatically invalid. This shows attention to edge cases and avoids wasted computation.

1. Understand the problem and constraints

Confirm the grid dimensions, obstacle representation, and that the target signature is a tuple of four distances (left, right, up, down). Clarify that a valid position requires an obstacle in every direction before the grid boundary.

2. Precompute distances in each direction

Perform four separate passes over the grid: left-to-right for left distances, right-to-left for right distances, top-to-bottom for up distances, and bottom-to-top for down distances. Use a large sentinel value (e.g., infinity) when no obstacle is encountered before the boundary.

3. Check for validity and match signature

Iterate through each cell, skip if any of the four distances is the sentinel (meaning no obstacle in that direction). Otherwise, compare the tuple of distances to the target signature and record the cell if they match.

4. Analyze complexity and optimize if needed

The approach runs in O(R*C) time and O(R*C) space, which is optimal for this problem. Discuss potential optimizations like early termination or using a single pass with state tracking if memory is a concern.

Key Points to Mention

  • Four directional passes to compute nearest obstacle distances efficiently.
  • Use of a sentinel value (e.g., infinity) to represent no obstacle before boundary.
  • Validity condition: all four distances must be finite (obstacle exists in each direction).
  • Time and space complexity: O(R*C) time and O(R*C) space, which is optimal.
  • Edge cases: obstacles at boundaries, empty grid, target signature with zero distances.
  • Potential follow-up: handling multiple target signatures or dynamic updates.

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

Q2

In a rooted tree where each node holds a character, for a given query node count how many path segments starting at that node and ending at any ancestor (including the node itself and the root) can be rearranged into a palindrome.

Algorithms & Data Structures
Author's notes

This one I actually liked, which is a weird thing to say about a problem that humbled me a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that a string can be rearranged into a palindrome if at most one character has an odd frequency. For each query node, traverse from that node up to the root, maintaining a frequency parity bitmask (e.g., 26-bit for lowercase letters). Count how many prefixes (from node to ancestor) have a bitmask with at most one set bit. Optimize by precomputing bitmasks from root to each node and using a hash map to count valid ancestor bitmasks for each query.

Pro tip: Mention that if queries are numerous, you can preprocess the tree to answer each query in O(depth) or even O(1) with offline processing, but always clarify the constraints first to choose the right trade-off.

1. Clarify the problem and constraints

Confirm the definition of a path segment (node to ancestor inclusive), the character set (e.g., lowercase English), and the number of queries and tree size to determine the required efficiency.

2. Identify the palindrome condition

Explain that a multiset of characters can form a palindrome iff at most one character has an odd count. Represent the parity of character counts as a bitmask.

3. Preprocess tree with bitmasks

Perform a DFS from the root, computing for each node the XOR bitmask of characters along the path from the root to that node. This allows O(1) computation of the bitmask for any ancestor-descendant path.

4. Answer queries efficiently

For a query node, the path to an ancestor has bitmask = mask[node] XOR mask[parent(ancestor)]. Count ancestors where this bitmask has at most one set bit. Use a hash map during DFS to maintain counts of bitmasks from root to current node, enabling O(1) per ancestor check.

5. Analyze complexity and edge cases

Discuss time complexity: O(N + Q * depth) naive, or O(N + Q) with offline processing. Handle edge cases: single node, all same characters, empty tree.

Key Points to Mention

  • Palindrome rearrangement condition: at most one character with odd frequency.
  • Bitmask representation of character parity (e.g., 26-bit integer for lowercase letters).
  • XOR operation to compute path bitmask from root to node.
  • Using a hash map to count valid ancestor bitmasks during DFS for efficient queries.
  • Time and space complexity trade-offs between per-query traversal and preprocessing.
  • Handling multiple queries efficiently, possibly with offline processing or caching.

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