Company: Squarepoint_25july

Difficulty: medium

Problem Statement

For two arrays a and b of equal length, the array correlation is defined as the sum of all values b[i] for which b[i] is strictly greater than a[i] . Given two integer arrays a and b of the same length n , rearrange the elements of array b so that the array correlation is as large as possible, and return that maximum possible array correlation value. You are not allowed to rearrange the elements of array a ; only b may be reordered. Input Format The first line contains a single integer n , the size of array a . Each of the next n lines contains one integer, the elements of a in order. The next line contains a single integer, the size of array b (equal to n ). Each of the next n lines contains one integer, the elements of b in order. Output Format Print a single integer: the maximum possible array correlation after optimally rearranging b . Constraints 1 <= n <= 2 * 10^5 1 <= a[i], b[i] <= 10^9 The answer can be as large as n * 10^9 , so it must be stored in a 64-bit integer

More Squarepoint_25july OA questionsInterview experiences