Solution (source code)

= Solution

If one <subgroup> contains the other, their union is the larger <subgroup>. Conversely, if neither contains the other, choose $h\in H\setminus K$ and $k\in K\setminus H$. If the union were a <subgroup> it would contain $hk$. If $hk\in H$, then $k=h^{-1}(hk)\in H$, a contradiction; if $hk\in K$, then $h=(hk)k^{-1}\in K$, again a contradiction. Thus
$$
\boxed{H\cup K\text{ is a subgroup}\ \Longleftrightarrow\ H\subseteq K\text{ or }K\subseteq H.}
$$
The <union of two subgroups> cannot generally be treated like their generated <subgroup>.