-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimum_Window_Substring.cpp
102 lines (58 loc) · 1.24 KB
/
Minimum_Window_Substring.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
This is an algorithm I thought of while trying to solve a problem during a CodeForces contest,but couldn't implement.
This algorithm uses a searching string and a query string that has to be searched in the searching string, and the minimum length of the window of the searched string has to be found out!
This code is yet to be completed!!!!!!!!!!!!!!!!!
*/
#include<bits/stdc++.h>
using namespace std;
int minseacrhwindow(string s,string q) {
int r=0,l=0;
int h=q.length();
vector<int> v;
while(r<s.length()) {
int p=r;
for(int i=0;i<h;i++) {
if(count(s.begin()+l,s.begin()+r,q[i])>0) {
continue;
}
else {
r++;
break;
}
}
if(r==p) {
v.eb(r-l+1);
}
else {
int a=l+1;
int f=0;
while(l<r-h) {
for(int i=0;i<h;i++) {
if(count(s.begin()+l,s.begin()+r,q[i])>0) {
continue;
}
else {
v.eb(r-l+1);
f=1;
break;
}
}
if(f==1) {
break;
}
l++;
}
}
}
sort(v.begin(),v.end());
return v[0];
}
int main() {
string s;
cin>>s;
string q;
cin>>q;
int y=minsearchwindow(s,q);
cout<<y;
return 0;
}