← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Uber SWE coding round, 60 minutes, two algorithm questions back to back. Nothing too exotic but the second one had enough edge cases to keep me on my toes.

Questions Asked (2)

Q1

Given an array of daily stock prices, find the maximum profit you can make from a single buy-sell transaction. If no profitable trade exists, return 0.

Algorithms & Data Structures
Author's notes

Classic question, knew it immediately.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose a single-pass solution that tracks the minimum price seen so far and the maximum profit. Explain the algorithm step-by-step, analyze its time and space complexity, and test with examples including no-profit scenarios.

Pro tip: Mention that you can solve it in one pass with O(1) space, which is optimal, and discuss how this approach scales to streaming data—a common follow-up at Uber.

1. Clarify requirements and edge cases

Ask if the array can be empty, contain negative prices, or if multiple transactions are allowed. Confirm that you must buy before selling and return 0 if no profit is possible.

2. Outline the optimal approach

Propose a single-pass algorithm that iterates through prices while keeping track of the minimum price seen so far and the maximum profit. Explain that this avoids nested loops.

3. Walk through the algorithm

Describe the initialization of min_price and max_profit, then for each price update min_price and compute potential profit, updating max_profit if larger. Use a small example to illustrate.

4. Analyze complexity and test

State that time complexity is O(n) and space is O(1). Test with cases like increasing prices, decreasing prices, and empty array to verify correctness.

5. Discuss extensions and trade-offs

Mention how the solution can be adapted for multiple transactions or streaming data, and compare with brute-force O(n^2) approach to highlight efficiency.

Key Points to Mention

  • Single-pass algorithm with O(n) time and O(1) space
  • Tracking minimum price and maximum profit
  • Handling edge cases: empty array, no profit, single element
  • Buy must occur before sell
  • Comparison with brute-force approach
  • Potential follow-ups: multiple transactions, streaming data

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

Q2

Given a binary tree, return its vertical order traversal as a list of lists, where nodes are grouped by column, sorted top to bottom within each column, and ties broken by node value ascending.

Algorithms & Data Structures
Author's notes

This one took more time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a BFS or DFS to traverse the tree while tracking each node's column index (root at 0, left child -1, right child +1). Store nodes in a hash map keyed by column, then sort columns and within each column sort by depth (top to bottom) and value (ascending) to handle ties. Finally, output the sorted lists of node values.

Pro tip: Clarify the tie-breaking rule upfront: if two nodes share the same column and depth, sort by value ascending. Also, mention that BFS naturally processes nodes top-to-bottom, but you still need to sort within columns if using DFS.

1. Clarify requirements and edge cases

Confirm the definition of vertical order: columns from leftmost to rightmost, nodes sorted top-to-bottom, ties by value ascending. Discuss edge cases like empty tree, single node, and duplicate values.

2. Choose traversal and track columns

Decide between BFS (queue) or DFS (recursion/stack) to traverse the tree. For each node, record its column index and depth (or rely on BFS order for depth).

3. Group nodes by column

Use a hash map where keys are column indices and values are lists of (depth, value) pairs. Alternatively, store nodes directly and sort later.

4. Sort and format output

Sort the column keys in ascending order. For each column, sort its nodes by depth ascending, then by value ascending. Extract the values into the final list of lists.

5. Analyze complexity and test

State time complexity: O(N log N) due to sorting (or O(N) if using BFS with ordered map). Space complexity: O(N). Walk through a small example to verify correctness.

Key Points to Mention

  • Column index assignment: root at 0, left child column-1, right child column+1.
  • Use of hash map to group nodes by column, with column as key.
  • Sorting within each column by depth (top to bottom) and then by value ascending for ties.
  • BFS naturally processes nodes level by level, ensuring top-to-bottom order if inserted in order.
  • Time complexity: O(N log N) due to sorting; can be O(N) with ordered map and BFS.
  • Edge cases: empty tree, single node, nodes with same column and depth.

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