← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Phone screen for a SWE role at Uber. Warm-up coding question but the follow-up discussion went deeper than I expected, so don't go in thinking it's a throwaway.

Questions Asked (1)

Q1

Given an array of daily stock prices, find the maximum profit you can make by buying on one day and selling on a later day. Return 0 if no profitable trade is possible.

Algorithms & Data Structures
Author's notes

Knew this one cold so I jumped straight to the linear scan approach, tracking the running minimum and updating max profit as I go.

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 an efficient one-pass solution that tracks the minimum price seen so far and computes the maximum profit at each step. Explain the algorithm clearly, analyze its time and space complexity, and discuss potential pitfalls or alternative approaches.

Pro tip: Mention that this is a classic 'buy low, sell high' problem and that the optimal solution runs in O(n) time with O(1) space, which is crucial for handling large datasets typical at Uber. Also, proactively discuss how you would handle edge cases like empty arrays or decreasing prices.

1. Clarify requirements and constraints

Ask about input size, whether prices can be negative, and if multiple transactions are allowed (though the problem states one). Confirm that buying and selling must be on different days and that no profit means return 0.

2. Outline a brute-force approach

Briefly mention that a naive solution would check all pairs of buy and sell days, resulting in O(n^2) time, which is inefficient for large inputs.

3. Propose an optimal one-pass algorithm

Explain that you can iterate through the array once, keeping track of the minimum price seen so far and the maximum profit that can be achieved by selling at the current price.

4. Analyze complexity and edge cases

State that the algorithm runs in O(n) time and O(1) space. Discuss edge cases: empty array, single element, strictly decreasing prices (profit 0), and strictly increasing prices (profit = last - first).

5. Test with examples

Walk through a small example, such as [7,1,5,3,6,4], to demonstrate how the algorithm works and verify the output (5 in this case).

Key Points to Mention

  • Time complexity: O(n) single pass
  • Space complexity: O(1) extra space
  • Tracking minimum price and maximum profit
  • Handling edge cases: empty array, no profit, single day
  • Comparison with brute-force O(n^2) approach
  • Real-world application: stock trading, but also similar patterns in data streams

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