Skip to content

Commit dfd4e3b

Browse files
authored
Update smallestdistinctwindow.cpp
1 parent 21a0564 commit dfd4e3b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Strings/smallestdistinctwindow.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace std;
99
string smallestWindow(string s,string p){
1010
unordered_map<char,int> freqp;
1111
for(char c:p){
12-
freqp[c]++;
12+
freqp[c]++; #taking in every character of the partial string
1313
}
1414
int distinct=freqp.size();
1515
unordered_map<char,int> freqw;
@@ -20,22 +20,22 @@ string smallestWindow(string s,string p){
2020

2121
while(r<s.length()){
2222
while(r<s.length() && count<distinct){
23-
freqw[s[r]]++;
23+
freqw[s[r]]++; #taking in the main string
2424
if(freqp.find(s[r])!=freqp.end() && freqw[s[r]]==freqp[s[r]]){
25-
count++;
25+
count++; #if the char matches than count increased
2626
}
27-
r++;
27+
r++; #increment uptil the main string length
2828
}
2929
while(l<=r && count==distinct){
3030
if(ans>r-l){
3131
ans=r-l;
3232
li=l;
3333
ri=r;
34-
flag=true;
34+
flag=true; #setting the flag true if window found
3535
}
3636
freqw[s[l]]--;
3737
if(freqp.find(s[l])!=freqp.end()&& freqw[s[l]]<freqp[s[l]]){
38-
count--;
38+
count--;
3939
}
4040
l++;
4141
}
@@ -52,4 +52,4 @@ int main(){
5252
string p="toc";
5353
cout<<smallestWindow(s,p);
5454
return 0;
55-
}
55+
}

0 commit comments

Comments
 (0)