As we can see X has all different elements as well as Y too. It is a case of X as distinguishable Objects and Y as distinguishable boxes so for onto functions, means there should be at least one element
It can be select 2 objects from first then 2nd then 3rd, or select one object then 2 objects and select 1 object or select 1, select 1 and select 2 objects so,
$C(4,2)C(2,1)C(1,1)+C(4,1)C(3,2)C(1,1)+C(4,1)C(3,1)C(2,2)=$
$\frac{4!}{2!\times 2!}\times\frac{2!}{1!1!}+\frac{4!}{3!\times 1!}\times\frac{3!}{2!1!}+\frac{4!}{3!\times 1!}\times\frac{3!}{2!1!}\times \frac{2!}{2!}$
$3\times \frac{4!}{2!1!1!}$ or in other way multiply $2!$ to both numerator and denominator so it becomes $\frac{4!3!}{2!2!1!1!} = 36$
Using Stirling number of the second kind : $j!S(4,3)$
$S(n,j) = \frac{1}{j!} \sum_{i=0}^{j-1}(-1)^i\binom{j}{i}(j-i)^n$
$=3!S(4,3) = \begin{bmatrix}\binom{3}{0}3^4-\binom{3}{1}2^4+\binom{3}{2}\end{bmatrix} = 36$
Answer is 36