We can solve this mathematically for the general case, which includes
n = 10.
Let's call our solution
p the subset of
s[i] > 0, that is, the set of represented numbers (any zero is a number or index that is not represented).
We can say that
n = sum of all frequencies = sum p
Now let's call
p' the subset of
s, which are frequencies only of numbers greater than zero.
sum p' = sum p - s = length p, which is simply the count of how many numbers in
s are greater than zero.
length p = length p' + 1. Now if
length p > 4, we know that
sum p' > 4 and we are left with an
m length partition (
p') that must sum to
m > 3. The only way this can be done is with
(m-1) 1's and one 2, e.g.,
[1,1,1,2] in the case of
m=4 (by definition there are no zeros in
p'). Such a partition could not make sense as a solution to our problem, and so we see that
p, or the subset of numbers greater than zero in our solution, must have less than 5 elements.
Now we can solve for specific cases:
Every solution must have
s > 0 since a zero in the zero column would invalidate the solution.
length p = 1 would only be possible if
s could be both zero and greater than zero at the same time.
length p = 2 implies
p' = , and so there are two zeros and two 2's,
length p = 3 implies
p' = [1,2]. Since we know there is only one more
s[i], which is
s > 0, the 2 in
p' must either refer to itself, in which case we have
s=[2,1,2,0,0]; or to two 1's and therefore
length p = 4, p' = [2,1,1]. In this case the 2 could only be referring to the two 1's and we must assume
s > 2, which also means
sum p >= (3+2+1+1 = 7). This is the final / general case:
s=2, s=1. The last 1 refers to
s and so its index equals
s. Remembering that
sum p - s = length p, we get,
s = n - 4, and the solution, for length p = 4, n > 6:
s=[n - 4,2,1...1,0,0,0]