Problem · Array
EasyAmazonFULLTIMEOA
See Amazon hiring insights

Problem 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:

  • The intersection of A and B is null.
  • The union of A and B equals the original array.
  • Subset A must be minimal in size.
  • The sum of A's weights is greater than the sum of B's weights.
  • Function

    packItems(arr: int[]) → int[]

    Complete the function packItems in the editor.

    packItems has the following parameter:

    1. 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

    drafts saved locally
    public int[] packItems(int[] arr) {
      // write your code here
    }
    
    arr[3, 7, 5, 6, 2]
    expected[6, 7]
    checking account