Get Minimum Boxes
Updated
Problem statement
The supply chain manager at one of Amazon's warehouses is shipping the last container of the day. All n boxes have been loaded into the truck with their sizes represented in the array boxes. The truck may not have enough capacity to store all the boxes though, so some of the boxes may have to be unloaded. Any boxes may be unloaded, and the order of the boxes does not matter; only the sizes of the remaining boxes are considered. The remaining boxes must satisfy the condition max(boxes) ≤ capacity * min(boxes).
Given the array boxes and the value capacity, find the minimum number of boxes that need to be unloaded so that the remaining boxes satisfy the condition.
Function
getMinimumBoxes(boxes: int[], capacity: int) → int Complete the function getMinimumBoxes in the editor.
getMinimumBoxes has the following parameters:
int[] boxes: an array of integers representing the sizes of the boxesint capacity: the capacity multiplier of the truck
Returns int: the minimum number of boxes that need to be unloaded
Examples
Example 1
boxes = [1, 4, 3, 2]capacity = 2return = 1Here boxes = [1, 4, 3, 2] and capacity = 2.
With all boxes loaded, max = 4 and min = 1, so max ≤ capacity * min becomes 4 ≤ 2 * 1 = 2, which is false.
Unload the box of size 1. The remaining boxes are [4, 3, 2] with max = 4 and min = 2, so 4 ≤ 2 * 2 = 4, which is true.
Only one box must be unloaded, so the answer is 1.
Constraints
1 ≤ n ≤ 10^51 ≤ boxes[i] ≤ 5 * 10^51 ≤ capacity
More Amazon interview questions
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Requests in WindowSalesforce · OASalesforce interview questions
- Earliest Hour with Frequent Badge AccessIntuit · OAIntuit interview questions
- Sliding Window MedianAuxoAI · OA
- Minimum Parking Roof LengthAmerican Express · OAAmerican Express interview questions
- Choose One from Each Set to Minimize the RangeInMobi · OAInMobi interview questions
- Integer Compression OffsetHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Sliding Window Average After Trimming Both EndsGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximize Element FrequencyGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Tagged Metric Window SumsDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions