Company: Amazon SDE on-campus_28april
Difficulty: medium
You are given an array arr of length n representing the target display value at each Amazon fulfillment station (stations are in a line from left to right). You can do the following operations any number of times (possibly zero): Choose an index i with 1 ≤ i ≤ n - 1 and set all positions 0, 1, ..., i - 1 to arr[i] ; this costs i × arr[i] . Choose an index i with 0 ≤ i ≤ n - 2 and set all positions i + 1, i + 2, ..., n - 1 to arr[i] ; this costs (n - 1 - i) × arr[i] . Compute the minimum total cost to make all array elements equal. Example n = 4 arr = [3, 1, 4, 2] Start with arr = [3, 1, 4, 2] . One optimal sequence is: Choose i = 1 and set position 0 to arr[1] = 1 . Cost = 1 * 1 = 1 . The array becomes [1, 1, 4, 2] . Choose i = 1 and set positions 2 and 3 to arr[1] = 1 . Cost = (4 - 1 - 1) * 1 = 2 . The array becomes [1, 1, 1, 1] . Total cost = 1 + 2 = 3 . No sequence yields a smaller total cost. Function Description Complete the function getMinCost in the edito