Maximum Number of Balanced Shipments
Learn this problemProblem statement
Amazon operates numerous distribution hubs for delivering its products. At one such hub, parcels are organized in a row where the ith parcel has a specific mass denoted by parcelWeights[i].
A shipment consists of a continuous subsequence of parcels from this arrangement. For example, given parcels with weights [3, 6, 3], possible shipments include [3], [6], [3], [3, 6], [6, 3], and [3, 6, 3]. However, [3, 3] is not considered a valid shipment as it is not contiguous.
A shipment is regarded as balanced if the mass of the last parcel in the shipment is not the greatest among all the parcels in that shipment. For instance, for a shipment with weights [3, 9, 4, 7], it is balanced because the last parcel's weight is 7, while the heaviest parcel weighs 9. Conversely, the shipment [4, 7, 2, 7] is not balanced.
Given a series of parcel weights, determine the highest number of balanced shipments that can be created such that each parcel is included in exactly one shipment, all shipments contain only a contiguous sequence of parcels, and every shipment remains balanced. Return 0 if no balanced shipments are possible.
Function
findMaximumBalancedShipments(parcelWeights: int[]) → intExamples
Example 1
parcelWeights = [1, 2, 3, 2, 6, 3]return = 2
Example 2
parcelWeights = [8, 5, 4, 7, 2]return = 2Example 3
parcelWeights = [4, 3, 6, 5, 3, 4, 7, 1]return = 3Constraints
1 <= n <= 10^51 <= parcelWeights[i] <= 10^9
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026