The continuous case is easier, but the same logic works here.

Then it gets messy.

Here you have to think about all the possible strings of length n of numbers 1 through k.

All sequences are equally likely.

To have exactly one 2 (and no 1's) that's

To have exactly two 2's (and no 1's) that's

Then exactly three 2's....

The sum of all of these will give you P(Y=2).

The last is easy.