File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ using namespace std;
9
9
string smallestWindow (string s,string p){
10
10
unordered_map<char ,int > freqp;
11
11
for (char c:p){
12
- freqp[c]++;
12
+ freqp[c]++; #taking in every character of the partial string
13
13
}
14
14
int distinct=freqp.size ();
15
15
unordered_map<char ,int > freqw;
@@ -20,22 +20,22 @@ string smallestWindow(string s,string p){
20
20
21
21
while (r<s.length ()){
22
22
while (r<s.length () && count<distinct){
23
- freqw[s[r]]++;
23
+ freqw[s[r]]++; #taking in the main string
24
24
if (freqp.find (s[r])!=freqp.end () && freqw[s[r]]==freqp[s[r]]){
25
- count++;
25
+ count++; # if the char matches than count increased
26
26
}
27
- r++;
27
+ r++; #increment uptil the main string length
28
28
}
29
29
while (l<=r && count==distinct){
30
30
if (ans>r-l){
31
31
ans=r-l;
32
32
li=l;
33
33
ri=r;
34
- flag=true ;
34
+ flag=true ; #setting the flag true if window found
35
35
}
36
36
freqw[s[l]]--;
37
37
if (freqp.find (s[l])!=freqp.end ()&& freqw[s[l]]<freqp[s[l]]){
38
- count--;
38
+ count--;
39
39
}
40
40
l++;
41
41
}
@@ -52,4 +52,4 @@ int main(){
52
52
string p=" toc" ;
53
53
cout<<smallestWindow (s,p);
54
54
return 0 ;
55
- }
55
+ }
You can’t perform that action at this time.
0 commit comments