Prove that $HK$ is a subgroup iff $HK=KH$. Let $H$ and $K$ be subgroups of a group $G$, and let $HK=\{hk: h
\in H, k \in K\}$, $KH=\{kh: k \in K, h \in H\}$. How can we prove that $HK$ is a subgroup iff $HK=KH$?

It is usually helpful to recall that $ L$ is a subgroup if and only if $ L^ 2=L $, $ L^{- 1}=  L $ and $  L\neq \varnothing$. 
If $HK$ is a subgroup, then $HK=(HK)^{-1}=K^{ -1}H^{-1}=KH$. Hence the condition is met. Conversely, 
$$ \begin{align}(HK)^{ -1} &= K^{ -1}H^{-1}\\&=KH =HK\text{, }\\(HK)(HK)=H(KH)K&=\\H( HK)K&=  H^2K^ 2=   HK\end{align} $$ and of course $ HK\neq \varnothing$. We made repeated use of the fact $ H $ and $ K $ are subgroups and $ H K = KH $.
