Solution (source code)

= Solution

Independence gives $\mathbb E[X_1(1-X_2)]=\theta(1-\theta)=\phi$, proving unbiasedness. Conditional on $K=k$, all binary sample strings with $k$ ones are equally likely. Therefore
$$
\mathbb E[X_1(1-X_2)\mid K=k]
=\frac kn\frac{n-k}{n-1}=\frac{k(n-k)}{n(n-1)}.
$$
The <Rao-Blackwell theorem>, or the tower property and total <variance> decomposition directly, yields the improved estimator
$$
\boxed{\widetilde\phi=\frac{K(n-K)}{n(n-1)}=\frac n{n-1}\widehat\phi.}
$$
It is unbiased by <conditional expectation> and is a function of the requested MLE. Its <variance> is strictly smaller, since
$$
\operatorname{Var}(X_1(1-X_2))
=\operatorname{Var}(\widetilde\phi)+\mathbb E[\operatorname{Var}(X_1(1-X_2)\mid K)].
$$
For $0<\theta<1$, the event $K=1$ has positive probability. On it, $X_1(1-X_2)$ has probability $1/n$ of being one, strictly between zero and one for $n\geq2$. Thus the final expectation is strictly positive. This proves \b[strict <variance> reduction], not merely a weak inequality.