Description
Solutions
Piles Of Boxes

Alex is given n piles of boxes of equal or unequal heights. In one step, Alex can remove any number of boxes from the pile which has the maximum height and try to make it equal to the one which is just lower than the maximum height of the stack. Determine the minimum number of steps required to make all of the piles equal in height.

Function Description

Complete the function pilesOfBoxes in the editor.

pilesOfBoxes has the following parameter(s):

  1. int boxesInPiles[n]: each boxesInPiles[i] represents the initial height of one pile

Returns

long: the minimum number of steps required

Example 1:

Input:  boxesInPiles = [5, 2, 1]
Output: 3
Explanation:

Initial State Step 1 Step 2 Step 3

In the first step, remove 3 boxes from boxesInPiles[0], and the new array is boxesInPiles' = [2, 2, 1]. Now reduce the two taller piles by 1 box each to match the height of the shortest pile. This takes 2 steps because each step is performed on only one pile. The final number of steps required is 3.

Constraints:
    ๐Ÿ…๐Ÿ…
Thumbnail 0
Testcase

Result
Case 1

input:

output: