FastPrepChoose Containers
Problems/Choose Containers

Choose Containers

IMC Trading logoIMC Trading● MediumNEW GRADINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged core task matches the photographed source at about 99%. The complete constraint list and both source examples are included.

You work for a pharmaceutical company that produces liquid medicine. Patients requiring these medications often require different amounts. To package the medication for delivery, you can choose between different sets of containers. Each container set specifies the sizes of containers it allows. For example, set 1 might offer containers with size 300 ml and 200 ml, while set 2 might offer containers with sizes 400 ml, 250 ml, and 100 ml.

When fulfilling a customer order for a given amount, a single container must be used and filled completely. If a container does not exist that matches the required amount, the next largest container is used. The extra medication included in that larger container, i.e. size of the container - required amount, is considered waste.

Your job is to evaluate different sets of containers and identify the set of containers that will minimize the total waste for a given collection of orders.

Return the zero-based index of the set of containers which minimizes the overall waste. If multiple sets provide the same minimum waste, return the lower index. If no set satisfies the required amounts, return -1.

Container data

The requirements array contains the requested sizes, and numContainerSets is the number of container sets. Each row of containers stores a container-set index followed by one container size.

The containers rows are given in set order: the sizes for set 0 are followed by the sizes for set 1, and so on. Within each set, the sizes are sorted in ascending order.

Function

chooseContainers(requirements: int[], numContainerSets: int, containers: int[][]) → int

Examples

Example 1

requirements = [4, 6, 6, 7]numContainerSets = 3containers = [[0, 3], [0, 5], [0, 7], [1, 6], [1, 8], [1, 9], [2, 3], [2, 5], [2, 6]]return = 0

The containers array is a 2D array where the first element is the container set id and the second is the size. In this case, the first set, id 0, has three containers with sizes 3, 5, and 7. The second set has containers with sizes 6, 8, and 9, and the third set has sizes 3, 5, and 6.

Using the first set, the losses are:

  • 5 - 4 = 1
  • 7 - 6 = 1
  • 7 - 6 = 1
  • 7 - 7 = 0

The total waste is 1 + 1 + 1 + 0 = 3 units.

Using the second set type, the losses are:

  • 6 - 4 = 2
  • 6 - 6 = 0
  • 6 - 6 = 0
  • 8 - 7 = 1

The total waste is 2 + 0 + 0 + 1 = 3 units.

The third set cannot be used because its maximum capacity is 6 and there is a requirement for 7.

Two sets of containers can be used that each result in 3 wasted units. The lower index set is at index 0.

Example 2

requirements = [4, 6]numContainerSets = 2containers = [[0, 5], [0, 7], [0, 10], [1, 4], [1, 10]]return = 0

Set 0 uses capacities 5 and 7 for requirements 4 and 6, wasting 1 + 1 = 2 units. Set 1 uses capacities 4 and 10, wasting 0 + 4 = 4 units. Return 0.

Constraints

  • 1 <= n <= 10^5, where n = requirements.length
  • 1 <= numContainerSets <= 10^4
  • 1 <= totalNumContainers <= 10^5, where totalNumContainers = containers.length
  • 1 <= requirements[i] <= 10^9
  • 0 <= containers[i][0] < numContainerSets
  • 0 <= containers[i][1] <= 10^9

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
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026
  • Minimum Space Wasted From PackagingOA · Seen Sep 2025

Similar questions at other companies

  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Calculating QuantilesIndeed · OAIndeed interview questions
  • Count Lamps Lighting Each PointCapital One · OACapital One interview questions
  • Minimum Cost to Make Array EqualWalmart · OAWalmart interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
  • Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
  • Minimum Seats for One-Way Car PoolingSquadStack.ai · OA
  • Find Sum of BeautiesAmazon · OA
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)

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)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int chooseContainers(int[] requirements, int numContainerSets, int[][] containers) {
      // write your code here
    }

}
Checking account…