![]() |
VOOZH | about |
Given two arrays A and B, a random pair is picked having an element from array A and another from array B. Output the probability of the pair being maximum weighted.
Examples:
Input : A[] = 1 2 3
B[] = 1 3 3
Output : 0.222
Explanation : Possible pairs are : {1, 1},
{1, 3}, {1, 3}, {2, 1}, {2, 3}, {2, 3},
{3, 1}, {3, 3}, {3, 3} i.e. 9.
The pair with maximum weight is {3, 3} with
frequency 2. So, the probability of random
pair being maximum is 2/9 = 0.2222.Below is the implementation:
0.222222
Time Complexity: O(n).
Auxiliary Space: O(1).