Skip to content

Commit 61cca00

Browse files
author
Sachan
committed
smallest window containing all chars of string
1 parent ecb990f commit 61cca00

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/string/SmallestWindowContainingAllChars.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ the constraint is met (that is, count equals to T‘s size), we immediately adva
3131
/*private static final String mainString = "this is a test string";
3232
private static final String subString = "tist";*/
3333

34-
private static final String mainString = "acbbaca";
34+
private static final String mainString = "acbbaca";
3535
private static final String subString = "aba";
3636

3737
public static void main(String[] strings) {
@@ -46,9 +46,11 @@ public static void main(String[] strings) {
4646
int count = 0;
4747
for (int k = 0; k < mainString.length(); k++) {
4848
hasFound[(int) mainString.charAt(k)] = hasFound[(int) mainString.charAt(k)] + 1;
49+
//find is meaningful only till all this condition, else they are extra not useful finds
4950
if (hasFound[(int) mainString.charAt(k)] <= toBeFound[(int) mainString.charAt(k)]) {
5051
count++;
5152
}
53+
//window is found for the first time
5254
if (count == subString.length() && !hasFoundOnce) {
5355
hasFoundOnce = true;
5456
end = k;
@@ -61,6 +63,7 @@ public static void main(String[] strings) {
6163
break;
6264
}
6365
}
66+
//window is found again
6467
} else if (hasFoundOnce && mainString.charAt(k) == mainString.charAt(begin)) {
6568
end = k;
6669
//remove useless from start

0 commit comments

Comments
 (0)