Find Minimum Replacements
Learn this problemProblem statement
In Amazon's distribution network, there are several drones with varying capacities, ranging from 1 to 10^9. Each j-th drone has a carrying capacity of j. The company needs to dispatch n packages, where the weight of the i-th package is given by pack[i].
During peak delivery times, only two drones are available to transport the packages, and they must alternate in their duties. This means that if Drone 1 handles the i-th package, Drone 2 must handle the (i + 1)-th package, and so on.
However, there may be challenges if the drones cannot handle certain package weights (i.e., some packages may be too heavy for a drone). To address this, Amazon can replace certain packages with others of a different weight to ensure that all packages are successfully delivered.
Given the ability to choose any two drones, your task is to determine the minimum number of replacements needed to ensure that all packages can be successfully delivered.
Function
findMinReplacements(parcels: int[]) → intComplete the function findMinReplacements in the editor.
findMinReplacements has the following parameter:
int pack[n]: an array representing the weights of packages.
Returns
int: the minimum number of replacements needed.
Examples
Example 1
parcels = [3, 1, 3, 2]return = 1Example 2
parcels = [1, 1, 1, 1]return = 2Constraints
- Each chosen drone has a carrying capacity in the range
1to10^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