Given a string <code>s</code>, return the <strong>maximum</strong> length of a <span data-keyword="substring">substring</span>&nbsp;such that it contains <em>at most two occurrences</em> of each character.
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;bcbbbcba&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">4</span></p>

<p><strong>Explanation:</strong></p>
The following substring has a length of 4 and contains at most two occurrences of each character: <code>&quot;bcbb<u>bcba</u>&quot;</code>.</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aaaa&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">2</span></p>

<p><strong>Explanation:</strong></p>
The following substring has a length of 2 and contains at most two occurrences of each character: <code>&quot;<u>aa</u>aa&quot;</code>.</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= s.length &lt;= 100</code></li>
	<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

def getKey(char):
    return ord(char) - ord('a')

class Solution:
    def maximumLengthSubstring(self, s: str) -> int:
        return self.maximumLengthSubstringBruteForce(s)
        char_counts = [0] * 26
        left = 0
        max_len = 0
        for right in range(len(s)):
            key = getKey(s[right])
            char_counts[key] += 1
            while char_counts[key] > 2:
                char_counts[getKey(s[left])] -= 1
                left += 1
            max_len = max(max_len, right - left + 1)
        return max_len

    def maximumLengthSubstringBruteForce(self, s: str) -> int:
        max_len = 0
        for i in range(len(s)):
            remaining_len = len(s) - i
            if remaining_len <= max_len:
                return max_len

            char_counts = {}
            for j in range(i, len(s)):
                char_counts[s[j]] = char_counts.get(s[j], 0) + 1
                if char_counts[s[j]] > 2:
                    break
                max_len = max(max_len, j - i + 1)
        return max_len

        
62