At Amazon, the team at the fulfillment center is responsible for the packaging process.
There is an array, item_weights
, of n
items to pack. The team needs to create a new array, new_arr
, by removing exactly n/3
items from item_weights
without changing the order of those remaining.
- The
sum_arr
of arraynew_arr
is defined as the sum of the weights or elements in the first half of the array minus the sum of the weights in the second half of the array. - Given
n
items and an arrayitem_weights
, find the maximumsum_arr
possible.
Function Description
Complete the function getMaxSumArr
in the editor below.
getMaxSumArr
has the following parameters:
int item_weights[n]
: item weights
Returns
int
: the maximum possiblesum_arr
.
Example 1:
Input:item_weights = [3, 2, 1]
Output:2
Explanation:
array item_weights | Removing element | array new_arr | sum_arr(new_arr) |
---|---|---|---|
[3, 2, 1] | index 2 (1-based) | [3, 1] | 3 - 1 = 2 |
[3, 2, 1] | index 1 (1-based) | [2, 1] | 2 - 1 = 1 |
[3, 2, 1] | index 3 (1-based) | [3, 2] | 3 - 2 = 1 |
sum_arr = 2
, which is the maximum.
Example 2:
Input:item_weights = [1, 3, 4, 7, 5, 2]
Output:4
Explanation:
Given n = 6
, item_weights = [1, 3, 4, 7, 5, 2]
, remove the elements 1
, 3
to leave new_arr = [4, 7, 5, 2]
.
Hence the sum will be (4 + 7) - (5 + 2) = 4
.
Constraints:
3 ≤ N ≤ 10^5
-10^4 ≤ item_weights[i] ≤ 10^4
n
is divisible by3
.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.