Consider a binary string of length $n$. We call the string good if the number of zeros and ones in the string are at most $m$.
Example: Let $n=4$ and $m=2$. Then the binary string 1010 is good, while the binary string 0010 is not.
Example: Let $n=4$ and $m=1$. Then no good string exists.
To count the number of good binary strings, one can use the following formula:
$$f(n,m) = \sum_{i=n-m}^{m} \binom{n}{i}$$
Mathematica derives the following closed-form for $f$:
$$\binom{n}{n-m} \cdot {}_{2}F_{1} \Big(1; -m; 1 - m + n; -1 \Big) - \binom{n}{m+1} \cdot {}_{2}F_{1} \Big(1; 1 + m - n; 2 + m; -1 \Big) \,,$$
where ${}_{2}F_{1}(a,b;c;z)$ is the hypergeometric function.
Now consider the same problem, this time for ternary strings of length $n$: The string is good if the number of zeros, ones, and twos in the string are at most $m$.
Example: Let $n=4$ and $m=2$. Then the ternary string 0120 is good, while 0001 is not.
To count the number of good ternary strings, one can use the following formula (which uses the notation for multinomial coefficients):
$$g(n,m) = \sum_{i=n-2m}^{m} \sum_{j=n-m-i}^{m} \binom{n}{i,j,n-i-j}$$
Q1. Is it possible to write the closed-form solution for $g(n,m)$ as we did for $f(n,m)$, perhaps using generalized hypergeometric function?
Q2. More generally, is it possible to derive closed-form solutions if the string is consist of $k$ symbols? ($k=2,3$ for binary and ternary strings, respectively)