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:
        
        result = 0
        
        if len(s) <= 2:
            return len(s)
        
        # initialize pointers
        pointer1 = 0
        pointer2 = 0
        
        # loop through each subarry of length 3
        d = {}
        while pointer1 < len(s):
            
            # reset if out of range
            if pointer2 >= len(s):
                length = len(s[pointer1:pointer2])
                
                if length > result:
                    result = length
                
                pointer1 += 1
                pointer2 = pointer1
                d = {}
                continue
                
            print(s[pointer1:pointer2])
            
            
            
            # UPDATE DICT VALUES
            if s[pointer2] in d:
                d[s[pointer2]] += 1
            else:
                d[s[pointer2]] = 1
            
            # check if max count reached
            if d[s[pointer2]] > 2:
                length = len(s[pointer1:pointer2])
                print(s[pointer1:pointer2])
                print(length)
                
                # update result
                if length > result:
                    result = length
                
                #reset 
                pointer1 += 1
                pointer2 = pointer1
                d = {}
                
            else:
                pointer2 += 1
                
        # return result 
        return result
        
111