Company: Factset
Difficulty: medium
Equalizing Box Piles Alex has n piles of boxes with varying heights. In each step, Alex can remove any number of boxes from the tallest pile to reduce its height to match the next tallest pile. Determine the minimum number of steps required to make all piles equal in height. Function Description Complete the function pilesOfBoxes which has the following parameter: vector<int> boxesInPiles : each boxesInPiles[i] represents the initial height of one pile Return long: the minimum number of steps required Constraints 1 ≤ n ≤ 2 × 10⁵ 1 ≤ boxesInPiles[i] ≤ 2 × 10⁶ Example 1 Sample Input n = 3 boxesInPiles = [5, 2, 1] Sample Output 3 Explanation 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. Example 2 Sample Input n = 2 boxesInPiles = [88