Let $H$ and $K$ be subgroups of a finite group $G$. Define $HK = \{hk\mid h \in H, k \in K\}$ and $KH = \{kh\mid k \in K, h \in H\}$.
a) Show that in general $HK \ne KH$. (For example, consider $G = S_4$ and let $H = (123)$ and $K = (14)$).
b) Prove that if $HK = KH$ then $HK$ is a subgroup of $G$. (Note: to say that $HK = KH$ does not mean that individual $h$ and $k$ commute. Rather it means that $hk = kh$ for some pair $k$, $h$.)
a) I know I have to show that $HK<KH$ and vice versa. But we dont know if $G$ is abelian, which would make this easy. Any ideas on how to go forward?
b) Proof: Assume $HK=KH$. So we have to show $h_1k_1h_2k_2\in HK$. So since we assumed that $HK=KH$, $k_1h_2=h_2k_1$ so $h_1k_1h_2k_2=h_1h_2k_1k_2$. Since $h_1h_2 \in H$ and $k_1k_2 \in K$, thus $h_1h_2k_1k_2 \in HK$. How do I show inverses for this one?
It is impossible to do a) as it is not true in general that $HK=KH$. Indeed, check it for the example you gave and you will see this; by check I mean compute all the products; presumably $H$ and $K$ are the groups generated by those elements it cannot be the elements themselves. Either you transcribed that wrong or there is a typo in the source (or some hypothesis is missing, but that is rather unlikely).
For b) Your argument is somewhat false. Read the remark again. You do not know $k_1h_2=h_2k_1$. But you know $k_1h_2= h' k'$ for some $h'$ in $H$ and $k'$ in $K$ and this is enough. For the inverse, since the groups is finite, once you know it is closed under the operation you already know it is a subgroup.