Leetcode 3090: Maximum Length Substring with two occurences
2 min readMay 3, 2024
In this exercise, we want to find the maximum substring that has at most 2 of any character.
Maximum substring problems
I am going to give you a secret tip just between us. When you see a maximum substring problem you should immediately think: “2-pointers”! You can thank me later.
Algorithm
We will just count the occurences of each character in an array. Whenever we encounter a character that is already 2-times in the substring…