Why is my ans wrong

Ans should by n^ (n-k) right ? What is wrong in my ans?

You don’t have that many cases. Try for a smaller scenario, n=4,k=2.
So after assigning the ones to each, you are left with 2.
Now the possible ways according to you are 2^2.
But actually it is 3
2 0
0 2
1 1.
I don’t know if you remember but this problem is similar to find the non - negative integral solutions of an equation.
x1 + x2 + x3 + … + xk = n
Now because all xi >= 1
you subtract k from the LHS.
and the resulting solution is (n-k+k-1) C (k-1)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.