← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE coding round with a discount pricing problem that's basically a monotonic stack question in disguise. Not a bad problem once you see it, but if you go in thinking brute force is fine you'll get stuck on the follow-up.

Questions Asked (1)

Q1

You're given a price list. For each item, find the first item to its right with a price less than or equal to it and subtract that from the original price. Output the total sum of all final prices, plus the indices of any items that had no discount applied.

Algorithms & Data Structures
Author's notes

The two-part output is what trips you up if you're not paying attention.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a classic 'next smaller or equal element' problem. Use a monotonic stack to efficiently find the first item to the right with price <= current for each item. Then compute the discounted prices, sum them, and collect indices of items with no discount.

Pro tip: Clarify edge cases upfront: what if multiple items have the same price? The problem says 'less than or equal', so equal prices count. Also, confirm whether the discount is subtracted from the original price or the already discounted price (it's original).

1. Understand the problem

Restate the problem in your own words: for each item, find the first item to its right with price <= current price; subtract that price from the current price; sum all final prices; and list indices (0-based or 1-based?) of items with no discount.

2. Choose the right data structure

Use a monotonic stack to find the next smaller or equal element for each item in O(n) time. The stack stores indices of items with prices in increasing order from bottom to top.

3. Algorithm walkthrough

Iterate through the price list. For each price, while the stack is not empty and the current price <= price at stack top, pop the top and record the current index as the next smaller or equal for that popped index. Push the current index onto the stack. After iteration, remaining indices have no discount.

4. Compute results

For each item, if it has a next smaller or equal, final price = original price - next price; else final price = original price. Sum all final prices. Collect indices of items with no discount.

5. Analyze complexity and edge cases

Time complexity O(n) because each index is pushed and popped at most once. Space O(n) for the stack. Discuss edge cases: empty list, single item, all increasing, all decreasing, duplicates.

Key Points to Mention

  • Monotonic stack technique for next smaller or equal element
  • Time and space complexity analysis (O(n) time, O(n) space)
  • Handling of equal prices (<= condition)
  • Edge cases: empty input, single element, strictly increasing/decreasing prices, duplicates
  • Output format: total sum and list of indices (clarify 0-based or 1-based)
  • Alternative approaches (e.g., brute force O(n^2)) and why monotonic stack is better

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