Find Binary permutations of given size not present in the Array | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findMissingBinaryString ( vector < string > & nums , int N ) { unordered_set < string > s ; int counter = 0 ; for ( string str : nums ) { s . insert ( str ) ; } int total = ( int ) 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 ) ) { num += '1' ; } else { num += '0' ; } } if ( s . find ( num ) != s . end ( ) ) { continue ; counter ++ ; } else { cout << num << " , ▁ " ; } } if ( counter == total ) { cout << " - 1" ; } } int main ( ) { int N = 3 ; vector < string > arr = { "101" , "111" , "001" , "011" , "100" , "110" } ; findMissingBinaryString ( arr , N ) ; return 0 ; }