Probability of a random pair being the maximum weighted pair |  ; Function to return probability ; Count occurrences of maximum element in A [ ] ; Count occurrences of maximum element in B [ ] ; Returning probability ; Driver code
import sys NEW_LINE def probability ( a , b , size1 , size2 ) : NEW_LINE INDENT max1 = - ( sys . maxsize - 1 ) NEW_LINE count1 = 0 NEW_LINE for i in range ( size1 ) : NEW_LINE INDENT if a [ i ] > max1 : NEW_LINE INDENT count1 = 1 NEW_LINE DEDENT elif a [ i ] == max1 : NEW_LINE INDENT count1 += 1 NEW_LINE DEDENT DEDENT max2 = - ( sys . maxsize - 1 ) NEW_LINE count2 = 0 NEW_LINE for i in range ( size2 ) : NEW_LINE INDENT if b [ i ] > max2 : NEW_LINE INDENT max2 = b [ i ] NEW_LINE count2 = 1 NEW_LINE DEDENT elif b [ i ] == max2 : NEW_LINE INDENT count2 += 1 NEW_LINE DEDENT DEDENT return round ( ( count1 * count2 ) / ( size1 * size2 ) , 6 ) NEW_LINE DEDENT a = [ 1 , 2 , 3 ] NEW_LINE b = [ 1 , 3 , 3 ] NEW_LINE size1 = len ( a ) NEW_LINE size2 = len ( b ) NEW_LINE print ( probability ( a , b , size1 , size2 ) ) NEW_LINE