Solution (source code)

= Solution

Suppose first that $H$ and $K$ are <normal subgroups>. For $h\in H$ and $k\in K$, the <commutator>
$$
[h,k]=hkh^{-1}k^{-1}
$$
lies in $H$, because $kh^{-1}k^{-1}\in H$, and in $K$, because $hkh^{-1}\in K$. Since $H\cap K=\{e\}$, $[h,k]=e$, so $h$ and $k$ commute.

Conversely, suppose every element of $H$ commutes with every element of $K$. Write an arbitrary $g\in G$ as $g=h_0k_0$. For $h\in H$,
$$
ghg^{-1}=h_0k_0hk_0^{-1}h_0^{-1}=h_0hh_0^{-1}\in H,
$$
so $H\trianglelefteq G$. The symmetric calculation proves $K\trianglelefteq G$.