近期发布,只有5天截止日期的真题。
Code Question 1
The developers at Amazon want to perform a reliability drill on some servers. There are n
servers, where the i
th server can serve request[i]
number of requests and has an initial health of health[i]
units.
Each second, the developers send the maximum possible number of requests that can be served by all the available servers. With each request, the developers can also send a virus to one of the servers that can decrease the health of a particular server by k
units. The developers can choose the server where the virus should be sent. A server goes down when its health is less than or equal to 0.
After all the servers are down, the developers must send one more request to conclude the failure of the application.
Find the minimum total number of requests that the developers must use to bring all the servers down.
Example
Consider n=2
, request = [3, 4]
, health = [4, 6]
, k = 3
.
The minimum number of requests required is 21.
No. of Servers | Total Requests | Virus | Server | Requests | New Health |
---|---|---|---|---|---|
1 | 4 | ||||
2 | 6 | ||||
... | ... | ... | ... | ... | ... |
![](https://csoahelp.com/wp-content/uploads/2024/06/image-28-1024x649.png)
Question 2
Amazon has multiple delivery centers for the distribution of its goods. In one such center, parcels are arranged in a sequence where the i
th parcel has a weight of weight[i]
.
A shipment is constituted of a contiguous segment of parcels in this arrangement. That is, for 3 parcels arranged with weights [3, 6, 3]
, a shipment can be formed of parcels with weights [3]
, [6]
, [3]
, [3, 6]
, [6, 3]
, and [3, 6, 3]
but not with weights [3, 3]
. These shipments are to be loaded for delivery and must be balanced.
A shipment is said to be balanced if the weight of the last parcel of the shipment is not the maximum weight among all the weights in that shipment. For example, shipment with weights [3, 9, 4, 7]
is balanced since the last weight is 7 while the maximum shipment weight is 9. However, the shipment [4, 7, 2, 7]
is not balanced.
Given the weights of n
parcels placed in a sequence, find the maximum number of shipments that can be formed such that each parcel belongs to exactly one shipment, each shipment consists of only a contiguous segment of parcels, and each shipment is balanced. If there are no balanced shipments, return 0.
Example
weight = [1, 2, 3, 2, 6, 3]
There are n = 6
parcels to ship. The parcels can be divided into two shipments: [1, 2, 3, 2]
and [6, 3]
, each of which is balanced. It can also be shown that this is the maximum number of shipments that can be formed. Thus, the answer is 2.
![](https://csoahelp.com/wp-content/uploads/2024/06/image-29.png)
Function Description
Complete the function findMaximumBalancedShipments
in the editor below.
findMaximumBalancedShipments
has the following parameter:
int weight[n]
: the weights of the parcels
Returns:
int
: the maximum possible number of balanced shipments that can be formed
![](https://csoahelp.com/wp-content/uploads/2024/06/image-30-1024x938.png)
Amazon NG 岗位的 OA 是一次重要的机会,抓住它可能是你成功进入大厂的第一步。希望这篇攻略能够帮助你更好地准备和应对这次挑战,祝你好运!
秒杀任意算法OA,AMAZON面试代面,请联系我们。
![](https://csoahelp.com/wp-content/uploads/2024/05/image-39.png)