Find Binary permutations of given size not present in the Array | Java 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
import java . util . * ; class GFG { static void findMissingBinaryString ( String [ ] nums , int N ) { HashSet < String > s = new HashSet < String > ( ) ; int counter = 0 ; for ( String str : nums ) { s . add ( str ) ; } int total = ( int ) Math . pow ( 2 , N ) ; String ans = " " ; for ( int i = 0 ; i < total ; i ++ ) { String num = " " ; for ( int j = N - 1 ; j >= 0 ; j -- ) { if ( ( i & ( 1 << j ) ) > 0 ) { num += '1' ; } else { num += '0' ; } } if ( s . contains ( num ) ) { counter ++ ; continue ; } else { System . out . print ( num + " , ▁ " ) ; } } if ( counter == total ) { System . out . print ( " - 1" ) ; } } public static void main ( String [ ] args ) { int N = 3 ; String [ ] arr = { "101" , "111" , "001" , "011" , "100" , "110" } ; findMissingBinaryString ( arr , N ) ; } }