Maximum Supplier Profit
Updated
Problem statement
There are n suppliers, and supplier i starts with stock[i] products. You make exactly m sales in total, and each sale removes one product from any supplier you pick that still has stock.
A sale pays you the chosen supplier's stock, counted just before the sale. Afterwards that supplier's stock goes down by 1.
Return the largest total amount of money you can earn.
The answer can be close to 10^18, so return it as a 64-bit integer.
Function
maximumSupplierProfit(stock: int[], m: int) → longExamples
Example 1
stock = [5,3]m = 5return = 17Call the suppliers A (stock 5) and B (stock 3). Sell from A twice: you earn 5, then 4, and A drops to 3. A and B now both have 3, so sell once from each (earn 3 + 3). Both now have 2, so the last sale earns 2. The total is 5 + 4 + 3 + 3 + 2 = 17.
Example 2
stock = [2,2,2]m = 6return = 9There are exactly 6 products, so every product is sold. Each supplier earns 2 + 1 = 3, and the total is 3 + 3 + 3 = 9.
Example 3
stock = [1000000000]m = 3return = 2999999997There is only one supplier. The three sales earn 1000000000 + 999999999 + 999999998 = 2999999997, which does not fit in a 32-bit integer.
Constraints
1 <= stock.length <= 10^51 <= stock[i] <= 10^91 <= m <= 10^9mis no larger than the sum of all values instock.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Furthest Building with Bricks and LaddersAmazon · PHONE SCREEN
- Minimum Full Glasses for an Exact Water VolumeMarshall Wace · PHONE SCREENMarshall Wace interview questions
- Server Upgrade PlanningRippling · OARippling interview questions
- Halve Values Until All Are at Most kAdobe · PHONE SCREENAdobe interview questions
- Minimum Time to Publish Comic BooksNutanix · OANutanix interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
Interview reports that mention this question
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)