The mathematicians of Hackerland want to determine a new statistic called array…
- User
The mathematicians of Hackerland want to determine a new statistic called array correlation. For two arrays a and b, each of the same size, array correlation is the sum of all b[i] where b[i]> a[i]. Given two arrays of integers a and b, rearrange the elements of b such that the array correlation is maximum. Note that it is not allowed to rearrange elements of the array a. Example: n = 5, a = [1, 2, 3, 4, 5], b = [3, 5, 4, 6, 2] b can be rearranged to [2, 3, 4, 5, 6]. Now, for each index, we have the integers of the array b greater than that of a. Thus the array correlation is 2 + 3 + 4+ 5+ 6 = 20. Function Description Complete the function getMaxArrayCorrelation in the editor below.
Sample Input For Custom Testing STDIN 5 → 1 3] 4 FUNCTION a[] size n = 5 → a = [1, 4, 2, 1, 3] → b[] size n = 5 → b = [2, 3, 1, 2, 2] Sample Output 7 Explanation The second array can be rearranged to b= [2, 1, 3, 2, 2]. b[i] > a[i] for i = 0, 3, and, 4, and the array correlation is 2 +3+2 = 7
- Assistant