<p>You are given a string <code>s</code> that consists of lowercase English letters.</p>

<p>A string is called <strong>special</strong> if it is made up of only a single character. For example, the string <code>&quot;abc&quot;</code> is not special, whereas the strings <code>&quot;ddd&quot;</code>, <code>&quot;zz&quot;</code>, and <code>&quot;f&quot;</code> are special.</p>

<p>Return <em>the length of the <strong>longest special substring</strong> of </em><code>s</code> <em>which occurs <strong>at least thrice</strong></em>, <em>or </em><code>-1</code><em> if no special substring occurs at least thrice</em>.</p>

<p>A <strong>substring</strong> is a contiguous <strong>non-empty</strong> sequence of characters within a string.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aaaa&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> The longest special substring which occurs thrice is &quot;aa&quot;: substrings &quot;<u><strong>aa</strong></u>aa&quot;, &quot;a<u><strong>aa</strong></u>a&quot;, and &quot;aa<u><strong>aa</strong></u>&quot;.
It can be shown that the maximum length achievable is 2.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;abcdef&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> There exists no special substring which occurs at least thrice. Hence return -1.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;abcaba&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> The longest special substring which occurs thrice is &quot;a&quot;: substrings &quot;<u><strong>a</strong></u>bcaba&quot;, &quot;abc<u><strong>a</strong></u>ba&quot;, and &quot;abcab<u><strong>a</strong></u>&quot;.
It can be shown that the maximum length achievable is 1.
</pre>

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

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

class Solution:
    def maximumLength(self, s: str) -> int:
        """
        You are given a string s that consists of lowercase English letters.

        A string is called special if it is made up of only a single character.

        For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are special.

        Return the length of the LONGEST special substring of s, which occurs at LEAST THRICE
        ,-1 if no special substring occurs at least thrice.

        A substring is a contiguous non-empty sequence of characters within a string.

        Summerize: string of lowercase english letters, want to identify, the longest special substring (aka contiuguous letters "aaaa", "z" "ff),
        which occurs at least 3 times. otherwise, -1
            - whats an example of a -1 case? abcdef, none of these characters occur 3 times


        EXAMPLE 1:
        s = "aaaa"
        output: 2
        notice its LONGEST, SUBSTRING, 3 TIMES
        "aa" "aa" "aa"
        "aaaa"

        len("aa") = 2
        "aa" "aa" "aa" = 3x 

        len("a") = 1
        "a" "a" "a" "a" = 4x

        maxSubstringLen = max(maxSubstringLen, len("a")) 

        EXAMPLE 2:
        abcdef
        a b c d e f (all happen one 1x), return -1

        EXAMPLE 3:
        abcaba
        a  a  a  3, contiguous "a", 3x
         b  b    2  contiguous "b", 2x
          c      1

        "optimized way"
        "bruteforce way": 
        aaaa
        {
            "a": 1
            "aa": 1
        }
        maxSubstring = ""
            if char[i] == char[j] and isSpecial(char[i],char[j]):
                special = 
                maxSubstring = max(maxSubstring)
                s[i:j+1] =
                j+=1
        aaaa 

                {
            "a": 4
            "aa": 3,
            "aaa": 2,
            "aaaa": 1,
        }
        max(hashMap.values()) >= 3:
            return True
        else:
            False
        """

        substringMap = {}
        for k in range(len(s)):
            i = k
            while i < len(s) and s[k] == s[i]:
                curSubstring = s[k:i+1]
                substringMap[curSubstring] = 1 + substringMap.get(curSubstring, 0)
                i += 1
                
        # TODO: rewrite this in a loop, because we want the key, not the value
        maxSubstring = 0
        for substring,val in substringMap.items():
            if val >= 3:
                maxSubstring = max(maxSubstring, len(substring))
        if maxSubstring == 0:
            return -1
        # im returning the frequency, but should return the len of the key
        return maxSubstring




64