<p>You are given a <strong>0-indexed</strong> string <code>word</code>, consisting of lowercase English letters. You need to select <strong>one</strong> index and <strong>remove</strong> the letter at that index from <code>word</code> so that the <strong>frequency</strong> of every letter present in <code>word</code> is equal.</p>

<p>Return<em> </em><code>true</code><em> if it is possible to remove one letter so that the frequency of all letters in </em><code>word</code><em> are equal, and </em><code>false</code><em> otherwise</em>.</p>

<p><strong>Note:</strong></p>

<ul>
	<li>The <b>frequency</b> of a letter <code>x</code> is the number of times it occurs in the string.</li>
	<li>You <strong>must</strong> remove exactly one letter and cannot choose to do nothing.</li>
</ul>

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

<pre>
<strong>Input:</strong> word = &quot;abcc&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> Select index 3 and delete it: word becomes &quot;abc&quot; and each character has a frequency of 1.
</pre>

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

<pre>
<strong>Input:</strong> word = &quot;aazz&quot;
<strong>Output:</strong> false
<strong>Explanation:</strong> We must delete a character, so either the frequency of &quot;a&quot; is 1 and the frequency of &quot;z&quot; is 2, or vice versa. It is impossible to make all present letters have equal frequency.
</pre>

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

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

class Solution:
    def equalFrequency(self, word: str) -> bool:
        cnter = Counter(word)
        if len(set(cnter.values())) > 2:  # If there are more than 2 unique frequencies, it's impossible to make all frequencies equal with a single removal
            return False
        mc = cnter.most_common()  # We will only ever remove the min or the max as those are the only 2 frequencies that there are, and this gives easy access to the min and max
        if mc[-1][1] == 1:      # Let's first tackle the min (i.e. "abbcc": if we remove the min of 'a' then we get "bbcc", which is equi-frequent in distribution)
            min_key = mc[-1][0]
            del cnter[min_key]  # Try removing the min key
            if len(set(cnter.values())) == 1:
                return True
            cnter[min_key] = 1  # If removing the min didn't work, then we need to try removing the max. We can't remove both, so we need to re-add the min_key back in.
        max_key = mc[0][0]      # Check if we only have one unique frequency, after removing the max key.
        cnter[max_key] -= 1
        return len(set(cnter.values())) == 1  # Since we stuck to 3 linear checks, this is O(n) time and O(n) space
    
	
        
19