cswork / OA打开练习工作台

AmazonOA #321

Pack Items

估计简单评测数据准备中,可先阅读题面

考点(AI 标注)贪心调度原地数组

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 Description 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

Example 1

Input:

arr = [3, 7, 5, 6, 2]

Output:

[6, 7]

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

Input:

arr = [4, 5, 2, 3, 1, 2]

Output:

[4, 5]

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

Input:

arr = [1, 2, 2, 2, 3, 4]

Output:

[1, 3, 4]

Explanation:

Example 4

Input:

arr = [2, 2, 2, 3]

Output:

[2, 2, 2]

Explanation:

Example 5

Input:

arr = [1,1,1,1,4,4,4,7,8]

Output:

[4,4,4,8]

Explanation: