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>

class Solution:
    def maximumLengthSubstring(self, s: str) -> int:
        char_counts = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
        def getMaxCharCount():
            max_found = 0
            for c in char_counts:
                max_found = max(max_found, char_counts[c])
            return max_found
        low = 0
        high = 0
        max_found = 0
        while low < len(s):
            if getMaxCharCount() <= 2:
                max_found = max(max_found, high - low)
            if getMaxCharCount() <= 2 and high != len(s):
                char_counts[s[high]] += 1
                high += 1
            else:
                char_counts[s[low]] -= 1
                low += 1
        return max_found
179