Input: A[] = {20, 30, 50}, B[]= {60, 40, 25}
Output: 2
Explanation:
Initially:
A[0] = 20 < B[0] = 60
A[1] = 30 < B[1] = 40
A[2] = 50 > B[2] = 25
Clearly, this arrangement has only 1 value such that A[i] > B[i].
This array A[] when rearranged to {20, 50, 30}:
A[0] = 20 < B[0] = 60
A[1] = 50 > B[1] = 40
A[2] = 30 > B[2] = 25
2 values follow the condition A[i] > B[i] which is the maximum for these set of arrays.
Input: A[] = {10, 3, 7, 5, 8}, B[] = {8, 6, 2, 5, 9}
Output: 4
Explanation:
Initially:
A[0] = 10 > B[0] = 8
A[1] = 3 < B[1] = 6
A[2] = 7 > B[2] = 2
A[3] = 5 = B[3] = 5
A[4] = 8 < B[4] = 9
Clearly, this arrangement has only 2 values such that A[i] > B[i].
This array A[] when rearranged to {10, 8, 5, 7, 3}:
A[0] = 10 > B[0] = 8
A[1] = 8 > B[1] = 6
A[2] = 5 > B[2] = 2
A[3] = 7 > B[3] = 5
A[4] = 3 < B[4] = 9
4 values follow the condition A[i] > B[i] which is the maximum for these set of arrays.