1224. Maximum Equal Frequency Hard
1/**
2 * [1224] Maximum Equal Frequency
3 *
4 * 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.
5 * 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).
6 *
7 * Example 1:
8 *
9 * Input: nums = [2,2,1,1,5,3,3,5]
10 * Output: 7
11 * 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.
12 *
13 * Example 2:
14 *
15 * Input: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]
16 * Output: 13
17 *
18 *
19 * Constraints:
20 *
21 * 2 <= nums.length <= 10^5
22 * 1 <= nums[i] <= 10^5
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/maximum-equal-frequency/
28// discuss: https://leetcode.com/problems/maximum-equal-frequency/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn max_equal_freq(nums: Vec<i32>) -> i32 {
34 0
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_1224() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.