← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber coding round, array manipulation problem with a discount rule baked in. Pretty standard stuff but the follow-up about efficiency tripped me up a bit.

Questions Asked (1)

Q1

Given an array of prices, apply a discount to each item where the discount equals the first price to its right that is less than or equal to it. If no such price exists, keep the original price. Return the resulting array.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Started with the brute force loop-within-a-loop approach and it worked fine.

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 finds the next smaller or equal element for each price in O(n) time. Walk through the algorithm with a small example, discuss trade-offs with a brute-force approach, and analyze time and space complexity.

Pro tip: Mention that the problem is essentially 'Next Smaller or Equal Element' and that a monotonic stack is the optimal pattern; also note that handling equal prices correctly is crucial because the condition is 'less than or equal to'.

1. Clarify the problem

Restate the problem in your own words and confirm details: discount equals the first price to the right that is <= current price; if none, keep original. Ask about input constraints (size, value range) and expected output format.

2. Discuss brute-force and optimal approaches

Acknowledge that a naive O(n^2) solution checks all pairs, but a monotonic stack can solve it in O(n). Explain that the stack maintains indices of prices in increasing order to efficiently find the next smaller or equal element.

3. Walk through the algorithm

Iterate through the array, and for each price, while the stack is not empty and the current price is <= the price at the stack's top index, pop and set the discount for that index to the current price. Push the current index onto the stack. After the loop, remaining indices have no discount.

4. Analyze complexity and edge cases

State that time complexity is O(n) because each element is pushed and popped at most once, and space complexity is O(n) for the stack. Discuss edge cases: empty array, single element, strictly increasing/decreasing arrays, and duplicate prices.

5. Test with examples

Walk through a small example like [10, 5, 3, 8, 7] to demonstrate the algorithm and verify the output. Mention that you would write unit tests for edge cases.

Key Points to Mention

  • Monotonic stack pattern for next smaller or equal element
  • Time and space complexity analysis (O(n) time, O(n) space)
  • Handling of equal prices correctly (<= condition)
  • Edge cases: empty array, single element, all increasing, all decreasing, duplicates
  • Trade-offs between brute-force O(n^2) and optimal O(n) solution
  • Potential follow-up: what if the array is streamed or very large?

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