Solution (source code)

= Solution

A <QR factorization> is $A=QR$, where $Q^TQ=I$ and $R$ is upper triangular. If $A$ is <orthogonal>, so is $R=Q^TA$. Its inverse is upper triangular, but $R^{-1}=R^T$ is lower triangular, forcing $R$ to be diagonal. <Orthogonality> then gives
$$
\boxed{R=\operatorname{diag}(\varepsilon_1,\ldots,\varepsilon_n),\quad\varepsilon_i\in\{1,-1\}}.
$$
With the customary positive diagonal convention, $R=I$.