Question: Code Question 2 Amazon has multiple delivery centers for the distribution of its goods. In one such center, parcels are arranged in a sequence where

Code 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 ith 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 shypment 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.
Code 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 ith 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
4
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.
Language ,C++20
Maps
Translate
Yuzu Sign in
Autocomplete Re
code in java |
Code Question 2
Amazon has multiple delivery centers and delivery warehouses all over the world! The world is represented by a number line from -109 to 109. There are n delivery centers, the the ?th one at location center[i]. A location x is called a suitable location for a warehouse if it is possible to bring all the products to that point by traveling a distance of no more than d. At any one time, products can be brought from one delivery center and placed at point x. Given the positions of n delivery centers, calculate the number of suitable locations in the world. That is, calculate the number of points x on the number line )x(109 where the travel distance required to bring all the products to that point is less than or equal to d.
Note: The distance between point x and center[i] is |x|-center[i]|, their absolute difference.
Examnle
The various locations along with the distance traveled to bring all treasures at that point are-
Locate the warehouse at x=-3 : First bring products from center[0]=-2 covering a distance of |-3-(-2)|=1 to reach the center and |-3-(-2)|=1 to return. Similarly we bring products from centers 1 and 2 to point -3 for total distance of 1+1+4+4+3+3=16 which is >d. This is not a suitable location.
 Code Question 2 Amazon has multiple delivery centers for the distribution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!