FastPrepMinimum Space Wasted From Packaging
Problems/Minimum Space Wasted From Packaging

Minimum Space Wasted From Packaging

IMC Trading logoIMC Trading● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading online assessment. The report links the first task of this assessment as a well-known public problem, Minimum Space Wasted From Packaging. The linked official definition gives this full runnable task and all three examples. Our version is about 99% the same as the named task. The report title mentions Grad and Intern. Its final employment label is Other, which does not map to one employment type. We use full-time because the catalog needs a value. It does not mean the report said so.

You have packages with positive integer sizes given by packages. Each package must go into its own box whose size is at least the package size.

There are suppliers described by boxes. The row boxes[j] lists the distinct box sizes offered by supplier j. Every offered size has an unlimited supply of boxes.

Choose exactly one supplier to pack every package. For a package of size p placed into a box of size b, the wasted space is b - p. Minimize the sum of wasted space over all packages by choosing the supplier and a box for each package.

Return -1 if no single supplier can pack all packages. Otherwise, return the minimum total wasted space modulo 1,000,000,007. Find the minimum using the true total before applying the modulo. Return the amount of wasted space, not a supplier index.

Complete minWastedSpace(packages, boxes).

Function

minWastedSpace(packages: int[], boxes: int[][]) → int

Examples

Example 1

packages = [2,3,5]boxes = [[4,8],[2,8]]return = 6

The first supplier uses two boxes of size 4 and one of size 8. Waste is (4-2)+(4-3)+(8-5)=6.

Example 2

packages = [2,3,5]boxes = [[1,4],[2,3],[3,4]]return = -1

Every supplier has maximum box size below 5, so the largest package cannot be packed.

Example 3

packages = [3,5,8,10,11,12]boxes = [[12],[11,9],[10,5,14]]return = 9

The third supplier uses sizes 5,5,10,10,14,14. Waste is 2+0+2+0+3+2=9.

Constraints

  • 1 <= packages.length <= 10^5.
  • 1 <= boxes.length <= 10^5.
  • 1 <= packages[i] <= 10^5.
  • 1 <= boxes[j].length <= 10^5.
  • 1 <= boxes[j][k] <= 10^5.
  • The sum of all supplier row lengths is at most 10^5.
  • Each supplier row contains distinct sizes. Package sizes may repeat, and neither input is guaranteed to be sorted.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Minimum Cost to Make Array EqualWalmart · OAWalmart interview questions
  • Use Minimum TokensAmazon · OA
  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Minimum Operations to Make All Array Elements EqualIBM · OAIBM interview questions
  • Calculating QuantilesIndeed · OAIndeed interview questions
  • Count Lamps Lighting Each PointCapital One · OACapital One interview questions
  • Maintain a Consistent-Hashing RingCohesity · ONSITE INTERVIEW
  • Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
  • Average Prices from Broker QuotesAkuna Capital · PHONE SCREENAkuna Capital interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int minWastedSpace(int[] packages, int[][] boxes) {
        // Write your solution here.
    }

}
Checking account…