Problem · Array
Pack Items
Learn this problemProblem statement
An amazon fulfillment associate has a set of items that need to be packed in two boxes, given an array of item weights (arr) to be placed, divide the item weights subsets A and B for packing into associate boxes while respecting the following conditions.
The conditions:
Function
packItems(arr: int[]) → int[]
Complete the function packItems in the editor.
packItems has the following parameter:
int[] arr: an array of integers representing item weights
Returns
int[]: an array of integers representing the weights of items in subset A
Examples
Example 1
arr = [3, 7, 5, 6, 2]return = [6, 7]Subset A = [6, 7] and Subset B = [3, 5, 2]. The intersection of A and B is null, the union equals the original array, A is minimal in size, and the sum of A's weights (13) is greater than the sum of B's weights (10).
Example 2
arr = [4, 5, 2, 3, 1, 2]return = [4, 5]Subset A = [4, 5] and Subset B = [2, 3, 1, 2]. The intersection of A and B is null, the union equals the original array, A is minimal in size, and the sum of A's weights (9) is greater than the sum of B's weights (8).
Example 3
arr = [1, 2, 2, 2, 3, 4]return = [1, 3, 4]🥲
Example 4
arr = [2, 2, 2, 3]return = [2, 2, 2]🥲
Example 5
arr = [1,1,1,1,4,4,4,7,8]return = [4,4,4,8]🥲
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026