I am not able to understand the editorial…
for(int i=0;i<len1;i++) {
hash_str[str[i]]++;
if(hash_pat[str[i]]!=0 and hash_str[str[i]]<=hash_pat[str[i]]){
count++;
}
if(count == len2) {
while(hash_str[str[start]]>hash_pat[str[start]] or hash_pat[str[start]]==0) {
if(hash_str[str[start]]>hash_pat[str[start]]) {
hash_str[str[start]]–;
}
start++;
}
int len_window = i-start+1;
if(len_window<min_len) {
min_len=len_window;
start_index = start;
}
}
}
what is happening in this part??
Not getting string window editorial
if(hash_pat[str[i]]!=0 and hash_str[str[i]]<=hash_pat[str[i]]){
count++;
}
in this part count is increased until all charcters are found in string of pattern.
1 Like
if(count == len2)
{
while(hash_str[str[start]]>hash_pat[str[start]] or hash_pat[str[start]]==0)
{
if(hash_str[str[start]]>hash_pat[str[start]])
{
hash_str[str[start]]--;
}
start++;
}
int len_window = i-start+1;
if(len_window<min_len) {
min_len=len_window;
start_index = start;
}
}
now if all characters are found of pattern ie. count == length of pattern then this part is executed. what we try to do in this part is start from begining we initiliaze start =0 and discard all the charcters from left side which are of no use so our string length get reduced. if we reach a charcter which is necessary then we stop here and note the length .... again for next start varbale will start from this index.
1 Like
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.