Number of permutations of k different items at n places such that every item is in the permutation In how many ways we can arrange k different items at n places such that every k item is at least at one place. n will always be greater than or equal to k.
eg.
When n = 2 and k = 1
We have (1,1)
Answer : 1
When n = 2 and k = 2
We have (1,2) and (2,1)
Answer : 2
When n = 3 and k = 2
We have (1,1,2),(1,2,1),(2,1,1),(1,2,2),(2,1,2) and (2,2,1)
Answer : 6
?
 A: Let $S(i)$ be the set of functions from $n$ to $k$, where $i$ is not in the range.
Then
$$
N(j)=\sum_{|A|=j}\left|\,\bigcap_{i\in A} S(i)\,\right|=\overbrace{\ \ \ \binom{k}{j}\ \ \ }^{\substack{\text{number of}\\\text{choices}\\\text{for }A}}\overbrace{\vphantom{\binom{k}{j}}\ (k-j)^n}^{\substack{\text{number of}\\\text{functions}\\\text{from $n\to k-j$}}}\tag{1}
$$
The Generalized Inclusion-Exclusion Principle says that the number of functions in $0$ of the $S(i)$ is
$$
\newcommand{\stirtwo}[2]{\left\{#1\atop#2\right\}}
\begin{align}
\sum_{j=0}^k(-1)^jN(j)
&=\sum_{j=0}^k(-1)^j\binom{k}{j}(k-j)^n\\
&=\sum_{j=0}^k(-1)^{k-j}\binom{k}{j}j^n\\
&=\sum_{j=0}^k\sum_{i=0}^j(-1)^{k-j}\binom{k}{j}\binom{j}{i}\stirtwo{n}{i}i!\\
&=\sum_{i=0}^k\sum_{j=i}^k(-1)^{k-j}\binom{k}{i}\binom{k-i}{j-i}\stirtwo{n}{i}i!\\
&=\sum_{i=0}^k(-1)^{k-i}\binom{k}{i}[k=i]\stirtwo{n}{i}i!\\[6pt]
&=\stirtwo{n}{k}k!
\end{align}
$$
Where $\stirtwo{n}{k}$ are Stirling Numbers of the Second Kind.

Examples from the question:
$\stirtwo{2}{1}1!=1$
$\stirtwo{2}{2}2!=2$
$\stirtwo{3}{2}2!=6$
A: Let $P(n,k)$ be the number of ways of doing this without the constraint that every number must appear at least once. Clearly $P(n,k) = k^n$.
Then note $P(n,k)$ contains $j^n$ arrangements containing only numbers from $1$ to $j$. So it might be tempting to say that there are $\binom{k}{j}j^n$ arrangements that only contain $j$ dfferent numbers or fewer however this is not the case. This is because if there are fewer than $j$ numbers used (say $l$) in the arrangement we can choose our $l$ numbers and then choose any other numbers we want and so each arrangement only using $l$ numbers is counted $\binom{k-l}{j-l}$ times.
Therefore $\sum_{l=1}^{j}\binom{k-l}{j-l}S(n,l) = \binom{k}{j}j^n$ where $S(n,l)$ is the number of arrangements using exactly $l$ different numbers. The answer to your question is $S(n,k)$.
Then by using inclusion exclusion we find $S(n,k) = \sum_{j=1}^{k}(-1)^{j+k}\binom{k}{j}j^n$.
Checking the $n=3,k=2$ case in your question gives $S(3,2) = \sum_{j=1}^{2}(-1)^{j}\binom{2}{j}j^3 = 8 - 2 = 6$ so it does indeed give the correct answer.
