Let $G$ be any group. It's a well-known result that if $H, K$ are subgroups of $G$, then $HK$ is a subgroup itself if and only if $HK = KH$.
Now, I've always wondered about a generalization of this result, something along the lines of:
Theorem: If $H_1, \ldots, H_n$ are subgroups of $G$, then $H_1H_2\dots{H_n}$ is a subgroup if and only if ($\star$) holds, where $(\star)$ is some condition on $H_1, \ldots, H_n$, preferably related to how the smaller products $H_{m_1}\ldots{}H_{m_k}$, for $k < n$, behave.
Question 1: Is there such a theorem?
I do know, and its easy to prove, that if $H_iH_j = H_jH_i$ for every $i, j$, then the big product is a group, but this is not satisfying since it's far from necessary (just take one of the groups to be $G$, and you need no commutativity at all). Also, I've been told that there is no really satisfactory answer; if that is indeed the case, then my question would be why? In particular:
Question 2: Are there really problematic counterexamples where you can see that the behavior of the smaller products has nothing to do with the big product, so that no such a theorem can ever exist?
I would appreciate even an answer for the particular case $n = 3$.
Thanks.