Find Binary permutations of given size not present in the Array | Python 3 program for the above approach ; 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
from math import pow NEW_LINE def findMissingBinaryString ( nums , N ) : NEW_LINE INDENT s = set ( ) NEW_LINE counter = 0 NEW_LINE for x in nums : NEW_LINE INDENT s . add ( x ) NEW_LINE DEDENT total = int ( pow ( 2 , N ) ) NEW_LINE ans = " " NEW_LINE for i in range ( total ) : NEW_LINE INDENT num = " " NEW_LINE j = N - 1 NEW_LINE while ( j >= 0 ) : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT num += '1' NEW_LINE DEDENT else : NEW_LINE INDENT num += '0' NEW_LINE DEDENT j -= 1 NEW_LINE DEDENT if ( num in s ) : NEW_LINE INDENT continue NEW_LINE counter += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( num , end = " , ▁ " ) NEW_LINE DEDENT DEDENT if ( counter == total ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE arr = [ "101" , "111" , "001" , "011" , "100" , "110" ] NEW_LINE findMissingBinaryString ( arr , N ) NEW_LINE DEDENT