π Following is the original prompt - π₯
Devs at AMZ are working on a new sorting algorithm for points on the x-axis of the coordinate system.
There are n points. The ith point initially has a weight of weight[i] and is located at position i on the x-axis.
In a single position, the ith point can be moved to the right by a distance of dist[i].
Given weight and dist, find the minimum number of operations required to sort the points by their weights.
Function Description π₯
Complete the function getMinOperations2 in the editor -
GetMinOperations2 has the following arguments -
Returns
long int: the min num of operations to sort the points. Here long int represents a 64 bit integer. :)
Examples
01 Β· Example 1
weight = [3, 6, 5, 2] dist = [4, 3, 2, 1] return = 5

Thus, the number of operations required are 1 + 2 + 2 = 5.
02 Β· Example 2
weight = [2, 4, 3, 1] dist = [2, 6, 3, 5] return = 4
Perform the ops on the first point twice and the second and the third points once. The final points are [4, 7, 3, 5] :)
Constraints
More Amazon problems
- 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 long getMinOperations2(int[] weight, int[] dist) {
// write your code here
}
weight[3, 6, 5, 2]
dist[4, 3, 2, 1]
expected5
sign in to submit