PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Compute final prices with next smaller discount

Last updated: Mar 29, 2026

Quick Overview

This question evaluates array-processing and algorithmic problem-solving skills, focusing on reasoning about subsequent elements to compute element-wise discounts under input constraints.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Compute final prices with next smaller discount

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an integer array `prices` of length `n`, where `prices[i]` is the original price of the `i`-th item. For each item `i`, find the first index `j > i` such that `prices[j] <= prices[i]`. That `prices[j]` becomes the discount for item `i`, so the final price of item `i` is: - `prices[i] - prices[j]` if such `j` exists - otherwise `prices[i]` Return an array `finalPrices` of length `n` containing the final price for each item. #### Input - `prices`: array of integers #### Output - `finalPrices`: array of integers #### Example - Input: `prices = [8, 4, 6, 2, 3]` - Output: `[4, 2, 4, 2, 3]` #### Constraints (typical) - `1 <= n <= 2e5` - `1 <= prices[i] <= 1e9`

Quick Answer: This question evaluates array-processing and algorithmic problem-solving skills, focusing on reasoning about subsequent elements to compute element-wise discounts under input constraints.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
Uber logo
Uber
Feb 11, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
5
0

You are given an integer array prices of length n, where prices[i] is the original price of the i-th item.

For each item i, find the first index j > i such that prices[j] <= prices[i]. That prices[j] becomes the discount for item i, so the final price of item i is:

  • prices[i] - prices[j] if such j exists
  • otherwise prices[i]

Return an array finalPrices of length n containing the final price for each item.

Input

  • prices : array of integers

Output

  • finalPrices : array of integers

Example

  • Input: prices = [8, 4, 6, 2, 3]
  • Output: [4, 2, 4, 2, 3]

Constraints (typical)

  • 1 <= n <= 2e5
  • 1 <= prices[i] <= 1e9

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.