3
bool hasAllCodes(string s, int k) {4
int n = pow(2, k), m = s.size();5
vector<bool> check(n, 0); // Check Array ,initially all value false;7
int val = 0; // Variable that will help in formation of binary to decimal8
// value of every substring.9
int i = 0, j = 0; // Sliding window ponter.12
val = val * 2 + (s[j] - '0'); // Form Binary ,Make it decimal.14
if (j - i + 1 < k) // If window size is Less than k ,just j++;16
else if (j - i + 1 == k) // If we hit k size.18
check[val] = true; // Mark check cval true.19
val = val - (s[i] - '0') * (pow(2, k - 1)); // Remove ith value's Calucaltion .21
j++; // and Increment j to maintain size of window as k25
for (int l = 0; l < n; l++) {26
if (check[l] == false) // If we didn't find any value ,means that susbtring is missing27
return false; // Return false;30
return true; // Return true;