Skip to content

Practice Maximum Equal Frequency

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1224
LeetCode Problem

Maximum Equal Frequency

Problem Statement

Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences. If after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).

Source: Maximum Equal Frequency on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,2,1,1,5,3,3,5]
Output
7

# Example 2

Input
nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]
Output
13

Constraints

2 <= nums.length <= 10^5
1 <= nums[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Maximum Equal Frequency.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.