Shortest Sublist With Max Frequency
You are given a list of integers nums
. Let k
be the frequency of a most frequent number in nums
. Return the length of a shortest sublist such that the frequency of its most frequent number is also k
.
Constraints
n ≤ 100,000
wheren
is the length ofnums
https://binarysearch.com/problems/Shortest-Sublist-With-Max-Frequency
Examples
Example 1
Input
- nums =
[1, 2, 3, 4, 3, 1]
Output
- answer =
3
Explanation
The most frequent numbers are 1
and 3
and each of them occur twice, so k = 2
. And the sublist [3, 4, 3]
is the shortest sublist such that the frequency of the most frequent number is equal to k
.
Leave a comment