Pairs whose concatenation contain all digits | Javascript 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 . ; Driver Code
let N = 20 ; function countPair ( str , n ) { let cnt = new Array ( 1 << 10 ) ; for ( let i = 0 ; i < cnt . length ; i ++ ) { cnt [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let mask = 0 ; for ( let j = 0 ; j < str [ i ] . length ; ++ j ) mask |= ( 1 << ( str [ i ] [ j ] - ' ' ) ) ; cnt [ mask ] ++ ; } let ans = 0 ; for ( let m1 = 0 ; m1 <= 1023 ; m1 ++ ) for ( let m2 = 0 ; m2 <= 1023 ; m2 ++ ) if ( ( m1 m2 ) == 1023 ) { ans += ( ( m1 == m2 ) ? ( cnt [ m1 ] * ( cnt [ m1 ] - 1 ) ) : ( cnt [ m1 ] * cnt [ m2 ] ) ) ; } return Math . floor ( ans / 2 ) ; } let n = 5 ; let st = [ " " , " " , " " , " " , " " ] ; document . write ( countPair ( st , n ) )