Check if a binary string contains all permutations of length k | C ++ Program to Check If a String Contains All Binary Codes of Size K ; Unordered map of type string ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define int  long long NEW_LINE bool hasAllcodes ( string s , int k ) { unordered_set < string > us ; for ( int i = 0 ; i + k <= s . size ( ) ; i ++ ) { us . insert ( s . substr ( i , k ) ) ; } return us . size ( ) == 1 << k ; } signed main ( ) { string s = "00110110" ; int k = 2 ; if ( hasAllcodes ) { cout << " YES STRNEWLINE " ; } else { cout << " NO STRNEWLINE " ; } }