This wrecked me for the first few minutes.
Model the problem as partitioning the n elements into groups of equal frequency, where each group corresponds to a distinct frequency value. To maximize the number of distinct frequencies, use the smallest possible frequencies 1, 2, 3, ... and find the largest k such that the sum 1+2+...+k ≤ n. Then derive the closed-form k = floor((sqrt(8n+1)-1)/2) and prove optimality by showing any additional frequency would require more than n elements.
Pro tip: Emphasize that the bound is tight and constructive: the example with frequencies 1, 2, ..., k and one leftover group (if any) achieves it. This shows you understand both the upper bound and its attainability, which interviewers value.
Clarify that we need the maximum number of distinct frequency counts among the distinct values in the array. Each distinct value has a frequency (a positive integer), and the sum of all frequencies equals n.
To maximize the number of distinct frequencies, we should use the smallest possible distinct positive integers: 1, 2, 3, ..., k. The sum of these must be ≤ n, so we need the largest k with k(k+1)/2 ≤ n.
Solve the quadratic inequality k^2 + k - 2n ≤ 0 to get k = floor((sqrt(8n+1)-1)/2). This is the maximum number of distinct frequencies.
Show that any set of k+1 distinct positive frequencies has sum at least 1+2+...+(k+1) = (k+1)(k+2)/2 > n, which is impossible. Thus k is an upper bound, and it is achievable by construction.
For a given n, construct an array with frequencies 1, 2, ..., k and one additional group with frequency n - k(k+1)/2 (if >0). For instance, n=10 gives k=4 (since 1+2+3+4=10), so an array with frequencies 1,2,3,4 works.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.