Company: Hilti_31july
Difficulty: medium
Equal towers Problem Description You are given an array A with N numbers, there are two types of operations that can use: Choose i < N such that A_i > A_{i+1}, decrease A_i by 1 and increase A_{i+1} by 1. Choose i < N such that A_i < A_{i+1}, increase A_i by 1 and decrease A_{i+1} by 1. Your task is to calculate the minimum number of operations needed to make all elements equal. Since the answer is large, print it modulo 10^9+7. If it is impossible to make all the elements equal, print -1. Complete the calculateMinimumOperations function in the editor below. It has the following parameter(s): Name: N Type: INTEGER Description: Number of elements Name: A Type: INTEGER ARRAY Description: Elements of the array Return: The function must return an INTEGER denoting the minimum number of operations needed to solve the problem, modulo 10^9+7. Examples Example 1: Input: 3 1 1 4 Output: 3 Explanation: Increase A[2] and decrease A[3], A = [1, 2, 3]. Example 2: Input: 3 5 2 5 Output: 2