Calculate Warehouse Efficiency
Problem statement
The supply chain manager at one of Amazon's warehouses wants to measure the efficiency of the way parcels are shipped. The volume of each parcel is represented in the array parcelWeights. Each day, the first and last parcels in the array parcelWeights are shipped until all of them are dispatched.
The manager comes up with metrics to calculate warehouse efficiency. Each day before shipping, any parcel in the warehouse is chosen and its volume is added to the sum of total efficiency. A parcel can only be chosen once.
Given the array parcelWeights, find the maximum possible efficiency of the warehouse.
Function
calculateWarehouseEfficiency(parcelWeights: int[]) → longExamples
Example 1
parcelWeights = [4, 4, 8, 5, 3, 2]return = 17
The parcels have selection deadlines [1, 2, 3, 3, 2, 1]. Select a weight-4 parcel by day 1, the weight-5 parcel by day 2, and the weight-8 parcel by day 3, for total efficiency 4 + 5 + 8 = 17.
Example 2
parcelWeights = [2, 1, 8, 5, 6, 2, 4]return = 23
Select weights 4, 6, 8, and 5 on the four shipping days. Their deadlines are compatible, and their sum is 23, which is the maximum possible.
Constraints
1 <= n <= 2 * 10^50 <= parcelWeights[i] <= 10^9