java.lang.Object
g1201_1300.s1224_maximum_equal_frequency.Solution

public class Solution extends Object
1224 - Maximum Equal Frequency.<p>Hard</p> <p>Given an array <code>nums</code> of positive integers, return the longest possible length of an array prefix of <code>nums</code>, such that it is possible to remove <strong>exactly one</strong> element from this prefix so that every number that has appeared in it will have the same number of occurrences.</p> <p>If after removing one element there are no remaining elements, it&rsquo;s still considered that every appeared number has the same number of ocurrences (0).</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,2,1,1,5,3,3,5]</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4] = 5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]</p> <p><strong>Output:</strong> 13</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxEqualFreq

      public int maxEqualFreq(int[] nums)