3090. Maximum Length Substring With Two Occurrences
Easy65.2% acceptance62,360 / 95,685 submissions
Asked by 3 companies
Topics
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: 4
Explanation:
The following substring has a length of 4 and contains at most two occurrences of each character:"bcbbbcba".Example 2:
Input: s = "aaaa"
Output: 2
Explanation:
The following substring has a length of 2 and contains at most two occurrences of each character:"aaaa".
Constraints:
2 <= s.length <= 100sconsists only of lowercase English letters.
Hints
Hint 1
We can try all substrings by brute-force since the constraints are very small.