← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Uber SWE interview that leaned hard into dynamic programming. Two parts to the same stock trading problem, starting simple and then ramping up. Not a bad experience but the second part took more thinking than I expected.

Questions Asked (2)

Q1

Given an array of daily stock prices, find the maximum profit you can make from at most one buy-sell transaction. Return 0 if no profit is possible.

Algorithms & Data Structures
Author's notes

Pretty standard stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints (e.g., array size, price range) and edge cases (empty array, decreasing prices). Then propose an O(n) time, O(1) space solution by tracking the minimum price seen so far and the maximum profit at each step. Walk through a small example to demonstrate correctness.

Pro tip: Mention that you can also solve it with Kadane's algorithm by treating price differences as an array, showing deeper algorithmic insight. Also, explicitly state that you handle the case of no profit by returning 0.

1. Clarify requirements and edge cases

Ask about input size, price range, and whether the array can be empty or have one element. Confirm that you must buy before selling and that you can choose not to transact.

2. Discuss brute force and its limitations

Mention the O(n^2) approach of checking all pairs to show you understand the problem, but note it's inefficient for large inputs.

3. Propose optimal one-pass solution

Explain that you can iterate once, keeping track of the minimum price seen so far and the maximum profit. Update profit when the current price minus minimum exceeds the current max profit.

4. Analyze complexity and edge cases

State that the solution runs in O(n) time and O(1) space. Handle edge cases like empty array (return 0) and strictly decreasing prices (return 0).

5. Test with examples

Walk through a sample array (e.g., [7,1,5,3,6,4]) to show how the algorithm works and verify the output (5).

Key Points to Mention

  • Time complexity: O(n) single pass
  • Space complexity: O(1) constant extra space
  • Track minimum price and maximum profit
  • Handle edge cases: empty array, single element, no profit
  • Alternative approach: Kadane's algorithm on price differences
  • Buy must occur before sell

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

Q2

Now extend the problem: you can make at most two non-overlapping buy-sell transactions. What is the maximum total profit achievable?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I slowed down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that this is the classic 'Best Time to Buy and Sell Stock III' problem. Then, explain that the optimal solution uses dynamic programming with four states representing the maximum profit after each action (first buy, first sell, second buy, second sell), updating them in a single pass. Alternatively, you can split the array at each possible point and combine the best single-transaction profits from left and right, but the DP approach is more elegant and efficient.

Pro tip: Mention that the DP states can be updated in-place with O(1) space, and emphasize that the order of updates matters to avoid using the same day for multiple transactions. Also, note that the problem can be generalized to k transactions, but for k=2 the state machine is simple and optimal.

1. Clarify the problem and constraints

Confirm that transactions are non-overlapping, you must buy before selling, and you can hold at most one stock at a time. Ask if you can buy and sell on the same day (usually no profit, but allowed).

2. Define DP states

Define four variables: buy1, sell1, buy2, sell2. buy1 is the max profit after first buy (negative cost), sell1 after first sell, buy2 after second buy, sell2 after second sell. Initialize buy1 and buy2 to -infinity, sell1 and sell2 to 0.

3. Iterate and update states

For each price p, update: buy1 = max(buy1, -p); sell1 = max(sell1, buy1 + p); buy2 = max(buy2, sell1 - p); sell2 = max(sell2, buy2 + p). The order ensures we don't use the same day for multiple transactions.

4. Return the result

After processing all prices, sell2 holds the maximum profit with at most two transactions. Return sell2.

5. Discuss complexity and alternatives

Time complexity O(n), space O(1). Mention the alternative of splitting the array and using two passes for left and right max profits, which is also O(n) time and O(n) space.

Key Points to Mention

  • Dynamic programming with state machine (four states)
  • In-place updates to achieve O(1) space
  • Order of updates to prevent overlapping transactions
  • Generalization to k transactions (optional)
  • Alternative approach: split array and combine left/right max profits
  • Edge cases: decreasing prices (profit 0), increasing prices (profit from one transaction)

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