Maximum Length Substring With Two Occurrences
Given a string s, return the maximum length of a substring such that it contains at most two occurrences of each character.
Example 1
Input
s = "bcbbbcba"Output
4A substring of length 4 can be chosen such that each character appears at most twice, and no longer valid substring exists.
Example 2
Input
s = "aaaa"Output
2The longest substring with at most two occurrences of each character is "aa", which has length 2.
Constraints
- 2 <= s.length <= 100
- s consists only of lowercase English letters.