← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber coding screen for a software engineer role, one algorithmic question the whole time. Pretty standard session, nothing fancy about the setup.

Questions Asked (1)

Q1

Given an array of item prices, return the final price of each item after applying a special discount rule: for each item, find the first later item whose price is less than or equal to the current item's price and subtract it as a discount. If no such item exists, the price stays the same.

Algorithms & Data Structures
Author's notes

I recognized this was a stack problem pretty fast, which felt good.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose a monotonic stack solution that processes the array from right to left to efficiently find the next smaller or equal element. Explain the algorithm, analyze its O(n) time and space complexity, and optionally discuss a brute-force alternative for comparison.

Pro tip: Emphasize the monotonic stack pattern as a reusable technique for 'next smaller element' problems, and mention that you'd validate with edge cases like strictly increasing/decreasing arrays and duplicates.

1. Clarify requirements and edge cases

Confirm the discount rule: find the first later item with price <= current price, subtract it; if none, price unchanged. Discuss edge cases: empty array, single item, all increasing, all decreasing, duplicates.

2. Propose efficient approach

Use a monotonic stack to track indices of items with increasing prices from right to left. For each item, pop stack elements with price > current price, then the top (if any) is the next smaller or equal element.

3. Walk through algorithm

Iterate from right to left, maintain a stack of indices with non-decreasing prices. For each index i, while stack not empty and prices[stack.top] > prices[i], pop. If stack not empty, discount = prices[stack.top]; else discount = 0. Push i onto stack.

4. Analyze complexity

Each element is pushed and popped at most once, so time complexity is O(n). Space complexity is O(n) for the stack in the worst case.

5. Discuss alternatives and trade-offs

Mention brute-force O(n^2) approach for small inputs or as a baseline. Highlight that the stack solution is optimal and can be adapted for similar problems.

Key Points to Mention

  • Monotonic stack pattern for next smaller or equal element
  • Right-to-left traversal to find the first later element
  • Time and space complexity analysis (O(n) time, O(n) space)
  • Handling duplicates correctly (using <= condition)
  • Edge cases: empty array, single element, strictly increasing/decreasing arrays
  • Comparison with brute-force approach and why stack is more efficient

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