Get Minimum Number of Moves (A.K.A. Weight Lifting Equipments:)π
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
1Example 1
blocks = [2, 4, 1, 3, 6].blocks = [2, 1, 4, 3, 6].blocks = [1, 2, 4, 3, 6].2Example 2
3Example 3

Constraints
Limits and guarantees your solution can rely on.
2 β€ n β€ 1051 β€ blocks[i] β€ 109 for all 1 β€ i β€ nblocks consists of distinct integers.