Find Binary permutations of given size not present in the Array | Function to find a Binary String of same length other than the Strings present in the array ; Map all the strings present in the array ; Find all the substring that can be made ; If num already exists then increase counter ; If not found print ; If all the substrings are present then print - 1 ; Driver Code
function findMissingBinaryString ( nums , N ) { let s = new Set ( ) ; let counter = 0 ; for ( let str of nums ) { s . add ( str ) ; } let total = Math . pow ( 2 , N ) ; let ans = " " ; for ( let i = 0 ; i < total ; i ++ ) { let num = " " ; for ( let j = N - 1 ; j >= 0 ; j -- ) { if ( i & ( 1 << j ) ) { num += " " ; } else { num += " " ; } } if ( s . has ( num ) ) { continue ; counter ++ ; } else { document . write ( num + " " ) ; } } if ( counter == total ) { document . write ( " " ) ; } } let N = 3 ; let arr = [ " " , " " , " " , " " , " " , " " ] ; findMissingBinaryString ( arr , N ) ;