Get Minimum Number of Moves (A.K.A. Weight Lifting Equipments:)π
See Amazon hiring insights
Imagine you are shopping on Amazon.com for some good weight lifting equipment. The equipment you want has blocks of many different weights that you can combine to lift.
The listing on Amazon gives you an array, blocks, that consists of n different weighted blocks, in kilograms. There are no two blocks with the same weight. The element blocks[i] denotes the weight of the ith block from the top of the stack. You consider weight lifting equipment to be good if the block at the top is the lightest, and the block at the bottom is the heaviest.
More formally, the equipment with array blocks will be called good weight lifting equipment if it satisfies the following conditions assuming the index of the array starts from 1:
blocks[1] < blocks[i] for all 2 β€ i β€ nblocks[i] < blocks[n] for all 1 β€ i β€ n-1In one move, you can swap the order of adjacent blocks. Find out the minimum number of moves required to form good weight lifting equipment.
Complete the function getMinNumMoves in the editor.
getMinNumMoves has the following parameter:
int blocks[n]: the distinct weights
Returns
int: the minimum number of operations required
blocks = [2, 4, 3, 1, 6] return = 3
blocks = [2, 4, 1, 3, 6].blocks = [2, 1, 4, 3, 6].blocks = [1, 2, 4, 3, 6].blocks = [4, 11, 9, 10, 12] return = 0
blocks = [3, 2, 1] return = 3

2 β€ n β€ 1051 β€ blocks[i] β€ 109 for all 1 β€ i β€ nblocks consists of distinct integers.- Minimum Delivery Center InconvenienceOA Β· Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA Β· Seen Jun 2026
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA Β· Seen Jun 2026
- Get Minimum AmountOA Β· Seen Jun 2026
- Drone Delivery RouteOA Β· Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
public int getMinNumMoves(int[] blocks) {
// write your code here
}