Items Purchase (For Java Backend Engineer)
Updated
Problem statement
n items where the price of the ith item is price[i]. A frequent customer has m discount coupons. If x discount coupons are used on the ith item, its price is reduced to the integer floor(price(i) / 2^x), e.g. floor(3/2^1) = floor(1.5) = 1.
Find the minimum amount needed to purchase all the items of the shop using at most m coupons.
Function
findMinimumPrice(price: int[], m: int) → int
Complete the function findMinimumPrice in the editor below.
findMinimumPrice has the following parameters:
int price[n]: the original prices of the itemsint m: the number of discount coupons
Returns
int: the minimum amount needed to purchase all items
Examples
Example 1
price = [2, 4]m = 2return = 3The optimum solution:
- Purchase item 1 for 2.
- Use 2 coupons on item 2, so the discounted price is 4/2^2 = 4 / 4 = 1.
The amount required = 2 + 1 = 3.
Constraints
1 <= n <= 10^50 <= m <= 10^91 <= price[i] <= 10^9
More PayPal interview questions
- Minimum Cost to Merge Values into OneOA · Seen Nov 2026
- Per-User Sliding-Window Rate LimiterOA · Seen Nov 2026
- Total Cost Against the Lowest Earlier PriceOA · Seen Nov 2026
- Find Minimum Price to SpendOA · Seen Oct 2024
- Modify ArrayOA · Seen Jun 2024
- Count User Logins 🌿 (Singapore)OA · Seen Mar 2024
- Similar Password 🪴 (Singapore)OA · Seen Mar 2024
- Can the Singer Perform the Song?PHONE SCREEN · Seen Jul 2025
Similar questions at other companies
- Task SchedulerAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Maximum K-Star SumC3.ai · OAC3.ai interview questions
- Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
- Maximum ScoreNVIDIA · OANVIDIA interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Task SchedulingJP Morgan Chase · OAJP Morgan Chase interview questions
- Decreasing SubsequencesGoogle · OAGoogle interview questions
- Get Maximum AmountIBM · OAIBM interview questions
- Optimize TikTok Reels ViewingTikTok · OATikTok interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions