Pairs whose concatenation contain all digits | Python3 Program to find number of pairs whose concatenation contains all digits from 0 to 9. ; Function to return number of pairs whose concatenation contain all digits from 0 to 9 ; Making the mask for each of the number . ; for each of the possible pair which can make OR value equal to 1023 ; Finding the count of pair from the given numbers . ; Driven Program
N = 20 NEW_LINE def countPair ( st , n ) : NEW_LINE INDENT cnt = [ 0 ] * ( 1 << 10 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT mask = 0 NEW_LINE for j in range ( len ( st [ i ] ) ) : NEW_LINE INDENT mask |= ( 1 << ( ord ( st [ i ] [ j ] ) - ord ( '0' ) ) ) NEW_LINE DEDENT cnt [ mask ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for m1 in range ( 1024 ) : NEW_LINE INDENT for m2 in range ( 1024 ) : NEW_LINE INDENT if ( ( m1 m2 ) == 1023 ) : NEW_LINE INDENT if ( m1 == m2 ) : NEW_LINE INDENT ans += ( cnt [ m1 ] * ( cnt [ m1 ] - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( cnt [ m1 ] * cnt [ m2 ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT return ans // 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE st = [ "129300455" , "5559948277" , "012334556" , "56789" , "123456879" ] NEW_LINE print ( countPair ( st , n ) ) NEW_LINE DEDENT