FastPrepMaximum Supplier Profit
Problems/Maximum Supplier Profit

Maximum Supplier Profit

Expedia logoExpedia● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report on Expedia's 2024 campus hiring for SDE interns says this was the one coding question in the first face-to-face round. For every sale you pick a supplier, it pays you its current stock, and the aim is the largest total over m sales. The problem card it links allows up to 10^5 suppliers and values of m and stock up to 10^9. The candidate's answer used a priority queue, and the follow-up was how long its push and pop steps take.

The report does not cover an m larger than the total stock. Here, m never goes above that total. We wrote the function and examples, and the answer is a 64-bit integer.

Our version is about 95% the same as the reported question.

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) → long

Examples

Example 1

stock = [5,3]m = 5return = 17

Call 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 = 9

There 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 = 2999999997

There 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^5
  • 1 <= stock[i] <= 10^9
  • 1 <= m <= 10^9
  • m is no larger than the sum of all values in stock.

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 SWE Intern Final Round: 126 Experiences (Part 1 of 6)

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)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public long maximumSupplierProfit(int[] stock, int m) {
        // Write your code here.
    }
}
Checking account…