Amazon relies on a network of drones, each equipped with a unique carrying limit ranging from 1 to10^9. The j-th drone can lift a max weight of j.
The company must transport n shipments, where the weight of the i-th shipment is given by parcels[i].
During peak delivery periods, only two drones are available, and they must alternate their deliveries. This means that if Drone X delivers the i-thshipment, then Drone Y must handle the (i + 1)-th, and they must continue switching back and forth.
However, some shipments may exceed a drone's capacity, making them undeliverable. To fix this, Amazon can swap certain shipments for ones with different weights to ensure that all deliveries are possible.
Given that Amazon can select any two drones for this task, determine the minimum number of replacements required to successfully deliver all shipments.
Complete the function findMinReplacements in the editor.
findMinReplacements has the following parameter:
int parcels[n]: an array representing the weights of packages.
Returns
int: the minimum number of replacements needed.
parcels = [3, 1, 3, 2] return = 1

parcels = [1, 1, 1, 1] return = 2

- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int findMinReplacements(int[] parcels) {
// write your code here
}