Company: Amazon off campus sde1_24march
Difficulty: medium
Developers at Amazon are working on a prototype to sync the data between multiple servers. There are n servers and the i th server has data[i] units of data. The data must be synced between every pair of servers. The cost of syncing server i and server j is min(data[i], data[j]) * abs(i - j) where abs(x) denotes the absolute value of an integer x . Indexing is 1-based. Given the array data , find the maximum cost of syncing the data between two servers. Since the answer can be large, report it modulo 10 9 +7. Example Suppose n = 3 and data = [1, 2, 3]. Server 1 Server 2 Cost 1 2 min(1, 2) * |1 - 2| = 1 1 3 min(1, 3) * |1 - 3| = 2 2 3 min(2, 3) * |2 - 3| = 2 ----- 2 -> data[] size n = 2 2 -> data = [2, 6] 6 Sample Output 2 Explanation The cost is min(2, 6) * |1 - 2| = 2. Sample Case 1 Sample Input For Custom Testing STDIN FUNCTION ----- -------- 3 -> data[] size n = 3 7 -> data = [7, 1, 2] 1 2 Sample Output 4 Explanation The maximum cost of syncing the data is between the fi