Idea
- We want to check for every single substring of the given string, and find the longest substring
- This can be optimised with two-pointers sliding window which allows us to go through all the valid substring of a string in O(n) time
- the substring is valid as long as the the substring size - highest freq character ≤ k, if bigger than k, it means no matter what we do we can’t get all repeating characters in that particular substring. In that case, we need to throw away the character at the left pointer, and include character at right pointer, hopefully can find a longer substring
Codes
- 1st attempt (go)
- 2nd attempt (java) ❤️
- 3rd attempt (java)