Company: Amazon_30july
Difficulty: medium
Calculate Minimum Cost Problem Description There is an integer array arr of size n . The cost of an array of size at least 2 is defined as the difference between the two minimum values in the array. Find the minimum cost over all subarrays of arr which have a size of at least 2. Note: A subarray is a contiguous part of the array. Complete the function calculateMinimumCost in the editor below. calculateMinimumCost has the following parameter: int arr[n] : an array of integers. Returns: int : the minimum cost over all subarrays of arr Examples Example 1: Input: arr = [7, 1, 8, 4] Output: 3 Explanation: Let's calculate the costs of each subarray of size at least 2. For subarrays of length 2: Subarray | Min values | Cost ---------|------------|----- [7, 1] | 1, 7 | 7 - 1 = 6 [1, 8] | 1, 8 | 8 - 1 = 7 [8, 4] | 4, 8 | 8 - 4 = 4 For subarrays of length 3: Subarray | Min values | Cost ------------|------------|----- [7, 1, 8] | 1, 7 | 7 - 1 = 6 [1, 8, 4] | 1, 4 | 4 - 1 = 3 For subarrays of len