10. Permutation in String
Generate all permutations and see if it is present
bool res = false;
bool checkInclusion(string s1, string s2) {
permute(s1, s2, 0);
return res;
}
void permute(string s1, string s2, int i) {
if(i >= s1.length()) {
if(s2.find(s1) != string::npos)
res = true;
} else {
for(int j = i; j < s1.length(); j++) {
swap(s1[i], s1[j]);
permute(s1, s2, i + 1);
swap(s1[i], s1[j]);
}
}
}Count number of chars in each window using map
Count number of chars in each window using lookup table
Last updated