[Amazon] OA -Maximum Sum Difference in Packing

Code Question 1

Amazon ships millions of packages every day. A large percentage of them are fulfilled by. Amazon, so it is important to minimize shipping costs. It has been found that moving a group of 3 packages to the shipping facility together is most efficient. The shipping process needs to be optimized at a new warehouse.

There are the following types of queries or requests:

  • INSERT package id: insert package id in the queue of packages to be shipped
  • SHIP-: ship the group of 3 items that were in the queue earliest i.e. they are returned in the order they entered,

Perform q queries and return a list of lists, one for every SHIP - type query. The lists are either:

  • 3 package ID strings in the order they were queued, or
  • if there are not enough packages in the queue to fulfill the query, the result is "N/A".

Note:

  • Initially, the queue is empty.
  • The list of packages shipped per group should be in the order they were queued.

The function performQueries takes List<List<>> of type String as a parameter which contains each query where:
list.get(i).get(0) = INSERT | SHIP
list.get(i).get(1) = shipmentID | -

Example Test Case:

5
2
INSERT GT23513413
INSERT TQC2451340
SHIP -
INSERT VYP8561991
SHIP

Expected result:

[N/A]
[GT23513413, TQC2451340, VYP8561991]

Code Question 2

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 array new_arr is defined as the sum of the weights of 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 array item_weights, find the maximum possible value of sum_arr.


Example
Given:
n = 3, item_weights = [3, 2, 1]

Array item_weightsRemoving ElementArray new_arrsum_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

The maximum sum_arr is 2, which is the highest score possible for array new_arr.


Function Description
Complete the function getMaxSumarr in the editor below.

getMaxSumarr has the following parameters:

  • int item_weights[n]: the array of item weights

Returns

  • int: the maximum possible sum_arr

Constraints

  • 3 <= n <= 100,000
  • -10,000 <= item_weights[i] <= 10,000
  • n is divisible by 3

Input Format for Custom Testing
For example:

Input:

6  
item_weights = [1, 3, 4, 7, 5, 2]  

Output:

4

Explanation: Removing the optimal items results in the highest sum_arr of 4.


我们长期稳定承接各大科技公司如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.

Leave a Reply

Your email address will not be published. Required fields are marked *