@@ -12,6 +12,7 @@ Once we have that, we need to basically prune it, remove the extra characters fr
12
12
Finally, we keep repeating this until we reach the end.
13
13
We can traverse the string via. two pointers, a left and right iterator.
14
14
Right is bound within the given string S and left is bound within the substring created by the right pointer.
15
+ This is an example of a sliding window.
15
16
16
17
To figure out if we have all the characters in this substring, we would have to count T via. a dictionary.
17
18
This is our known count that is required for each substring.
@@ -28,7 +29,7 @@ When the question wants the actual substring and not a count, even using a deque
28
29
So this implementation is technically ** O(S * (S+T))** due to python.
29
30
30
31
When implementing these type of two pointer questions.
31
- I recommend to avoid using indexes as much as possible and use iterators.
32
+ I recommend to ** avoid using indexes as much as possible and use iterators** .
32
33
It is very easy to get a one off error doing these and within a 30 minute timeframe, it is very risky.
33
34
Just talk about using indexes instead and you will be fine.
34
35
@@ -76,10 +77,10 @@ This will represent the number of unique valid characters of T.
76
77
If T = 'abcc', then there are 3 keys in the dictionary.
77
78
When ever we increment a key in the dictionary, we can then compare the dictionary T's count with dictionary S's count.
78
79
If S's count equals exactly what T's count is, then we just got one of the 3 keys validated.
79
- If we decrement, and S's count is T's count-1, then we just unvalided one of those keys.
80
+ If we decrement, and S's count is T's count-1, then we just unvalidated one of those keys.
80
81
81
- This will remove the need to traverse all the keys whenever we need to validate the substring.
82
- Hence, this validation will run at O(1).
82
+ This will remove the need to traverse all the keys whenever we need to revalidate the substring.
83
+ Hence, this validation will run at O(1). String slicing will still slow us down however.
83
84
84
85
```
85
86
from collections import defaultdict
0 commit comments