Mark As Completed Discussion

The brute force way to approach this would be to iterate through the string, while looking at all the substrings of length 3. Then, we'd check to see if they contain the characters that you're looking for.

And then, if you can't find any substring of length 3, then try all substrings of length 4, and 5, and 6, and so on. You continue until you try options reaching the length of the string. But if you reach that point, you already know that the characters "ABC" are contained within it-- seems inefficient!

Furthermore, this approach is not very optimal as it runs in quadratic time or O(N²) time complexity. We would want a more optimal solution!

This is where the idea of a sliding window would come in.

The window would represent the current section of the string that you are looking at (which substring you're examining). It would have 2 pointers, one representing the start of the window and one representing the end.

SNIPPET
1Left pointer at 'A' represents start
2Right pointer at 'O' represents end
3
4A   D  O  B  E  C  O  D  E  B  A  N  C
5
6^      ^