Solution (source code)

= Solution

Take the first entry into the stopping region:
$$
\tau^*=\inf\{t\leq T:U_t=Z_t\}.
$$
This set is nonempty because $U_T=Z_T$. Before $\tau^*$, the recursion has
$$
U_t=\mathbb E[U_{t+1}\mid\mathcal F_t],
$$
so the stopped process $U_{t\wedge\tau^*}$ is a martingale. Optional sampling and $U_{\tau^*}=Z_{\tau^*}$ give
$$
U_0=\mathbb E U_{\tau^*}=\mathbb E Z_{\tau^*}.
$$
Thus $\tau^*$ is an <optimal stopping time>.