------
## 最终结论
```python
def maxEqualFreq(nums):
    count = {}
    freq = {}
    max_length = 0

    for i in range(len(nums)):
        num = nums[i]

        # Update the count of the current number
        if num in count:
            old_count = count[num]
            count[num] += 1
            new_count = count[num]

            # Update frequency dictionary
            freq[old_count] -= 1
            if freq[old_count] == 0:
                del freq[old_count]
            if new_count in freq:
                freq[new_count] += 1
            else:
                freq[new_count] = 1
        else:
            count[num] = 1
            if 1 in freq:
                freq[1] += 1
            else:
                freq[1] = 1
        
        # Check if we can remove one element to make frequencies equal
        if len(freq) == 1:
            only_freq = next(iter(freq))
            if only_freq == 1 or freq[only_freq] == 1:
                max_length = i + 1
        elif len(freq) == 2:
            keys = list(freq.keys())
            key1, key2 = keys[0], keys[1]
            if (key1 == 1 and freq[key1] == 1) or (key2 == 1 and freq[key2] == 1) or \
               (abs(key1 - key2) == 1 and (freq[key1] == 1 or freq[key2] == 1)):
                max_length = i + 1

    return max_length
```