#1224
Maximum Equal Frequency
master · 1770 · lc hard +32 · verified · 38% accepted · 565 likes · top 17%
Description
Given an array nums of positive integers, find the longest prefix of nums such that removing exactly one element from that prefix causes every value that appeared to have the same occurrence count.
If removing one element leaves the prefix empty, it is still considered valid.
Example 1:
Input: nums = [2,2,1,1,5,3,3,5]
Output: 7
Explanation: 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.
Example 2:
Input: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]
Output: 13
Code
1
2
3