Find all $4$ digit numbers such that sum of digits is $11$. Find all $4$ digit numbers such that sum of digits is $11$.
\begin{cases} x_1+x_2+x_3+x_4=11\\ 1\leq x_1{\leq 9}\\ 0\leq x_2{\leq 9}\\0\leq x_3{\leq 9}\\ 0\leq x_4{\leq 9}\end{cases}.
Using  stars and bars there is 13 choose 3 ways to do. So we get $286$ but answer is $279$. I saw this same question in the forum but didn't fully understand solution. Where we are overcounting when solving in this way? And mainly what we are overcounting?
 A: As stated by Stinking Bishop in the comments, you are overcounting e.g. the "number" $(x_1, x_2, x_3, x_4) = (11, 0, 0, 0)$. The problem is that your stars and bars method does not account for your stated constraints $0\leq x_i\leq 9$.
Therefore, we need to subtract the extra cases where one of the digit is at least $10$. If there's a $10$, it must be some permutation of $(10, 1, 0, 0)$, so there are $6$ cases (note that $0$ cannot be first digit). If there's a $11$, then it must be $(11, 0, 0, 0)$, so there is $1$ case here. Therefore, there is $286 - 6 - 1 = 279$ cases in total.
Challenge for you: Do the same problem for sum of digits $S = 12$ and $13$. There should be $342$ and $405$ respectively.
A: In this answer it is described how to solve this by generating functions. The solution is the coefficient of the degree $11$ monomial of the polynomial
$$(x+x^2+\cdots+x^9)(1+x+x^2+x^3+\cdots+x^9)^3$$
This coefficient can be calculated by a CAS like  Mathematica as shown in the link above. It can even calculated by a numerical calculator that can handle arbitrary length integers as describe in the second half of my answer here. But in this answer I learned in one of the comments how to calculate this by hand.
Note that
$$\frac 1 {1-x}=\sum_{n=0}^\infty x^n$$
and by differentiation using induction you get
$$\frac 1 {(1-x)^k}=\sum_{n=0}^\infty{ n+k-1 \choose k-1} x^n$$
So we have
$$(x+x^2+\cdots+x^9)(1+x+x^2+x^3+\cdots+x^9)^3\\
=x\frac{1-x^9}{1-x}\frac{(1-x^{10})^3}{(1-x)^3}\\
=x(1-x^9)(1-x^{10})^3 \sum_{n=0}^\infty{ n+3 \choose 3} x^n\\
=(x-x^{10}-3x^{11}+3x^{20}+\cdots)\frac 1 6 (1\cdot2\cdot3+2\cdot 3 \cdot4\cdot x+\cdots+11\cdot 12\cdot 13\cdot x^{10} \cdots )\\
=\cdots +\cdot \frac 1 6 (-3\cdot 1\cdot 2 \cdot 3-2\cdot 3\cdot 4+11\cdot 12 \cdot 13)x^{11}+\cdots\\
=\cdots+279x^{11}+\cdots$$
The coefficients of the monomials of degree greater than $36$ cancel out.
We have
$$
\frac{\left( {{x}^{40}}-{{x}^{31}}-3 {{x}^{30}}+3 {{x}^{21}}+3 {{x}^{20}}-3 {{x}^{11}}-{{x}^{10}}+x\right) \, \sum_{n=0}^{\infty }{\left. \left( {{n}^{3}}+6 {{n}^{2}}+11 n+6\right)  {{x}^{n}}\right.}}{6}
$$
We abbreviate
$$f(n):={{n}^{3}}+6 {{n}^{2}}+11 n+6$$
and verify that
$$f(n+39)-f(n+30)-3f(n+29)+3f(n+20)+3f(n+19)-3f(n+10)-f(n+9)+f(n)=0$$
and
$$f(n+39)-f(n+30)-3 f(n+29)+3 f(n+20)+3 f(n+19)-3 f(n+10)-f(n+9)$$
for $n=-1,-2,-3$ because $f(n)=0$ for this values
A: As is usual, in using stars and bars, we often need to apply inclusion-exclusion if there is an upper limit.
Here there are also differing lower limits, so we will first equalize the lower limits by preplacing a digit in $x_1$, so
$\;x_1+x_2+x_3+x_4 = 10,$
and upper limit becomes $8$ for $x_1$ and $9$ for the rest, so if we put $9$ in the first digit or $10$ in any other, they are the  "bad" cases to be excluded.
and we get $\binom{13}3 -\binom 11\binom{13-9}3 - \binom31\binom{13-10}3 = 279$

The other alternative is to use generating functions, and find the coefficient of $x^{11}$ in
$(x^1+x^2+x^3+...+x^9)(x^0+x^1+x^2+x^3+...+x^9)^3$
with the first multiplicand standing for the first digit, yielding the same answer of $279$
