
This Uber OA was taken on HackerRank. The two questions are standard patterns, but both require clean implementation under time pressure.
Q1: Price Discount with Monotonic Stack
Core idea
Use a monotonic stack and iterate from right to left:
- Store indices in the stack
- Keep stack prices monotonically increasing
- For each index
i, use the stack top as the first valid discount candidate on the right (first value<= current)
Then maintain three outputs required by the statement:
discount[i]: discount for itemitotal: final total price after discountsfullPriceIdx: indices of items bought at full price
Return total and full-price indices based on the problem format.
Complexity
- Time:
O(n) - Space:
O(n)
Q2: Connectivity Time / Number of Components (Union-Find)

Essence
This is a connected-components problem. Use Union-Find directly.
Group-and-merge method
Group points by x and by y:
- Same
xmeans same row - Same
ymeans same column
Then sort and merge in both dimensions:
- In each row group, sort by
y; union adjacent valid pairs that satisfy the constraint - In each column group, sort by
x; union adjacent valid pairs that satisfy the constraint
Finally, count distinct roots (number of disconnected components), then convert to the asked time/result format.
Complexity
Let n be number of points:
- Grouping + sorting dominates: usually
O(n log n) - Union-Find operations: near
O(n α(n)) - Overall:
O(n log n)
Common mistakes in interview
- Q1 monotonic condition reversed
- Q1 forgetting to maintain
totalandfullPriceIdxconsistently - Q2 doing row unions but forgetting column unions
- Q2 unioning after sort without checking the required constraint
One-line takeaway
Q1 is a classic monotonic-stack template; Q2 is grouping + sorting + Union-Find. Keep state updates clean and this set is very manageable.
If you are not fully confident about Uber OA, support is available. You can also ask about other companies.
#uber #internationalstudents #newgrad #internship #jobsearch #hackerrank #interviewrecap
Further Reading (External Links)
Need real interview questions? Contact WeChat Coding0201: Get Questions.
Contact
Email: [email protected]
Telegram: @OAVOProxy