Solution (source code)

= Solution

Put $q=1-p$. Since
$$
\mathbb E\!\left[\lambda^{S_{n+1}}\mid\mathcal F_n\right]
=\lambda^{S_n}\left(p\lambda+q\lambda^{-1}\right),
$$
the <martingale> condition is
$$
p\lambda^2-\lambda+q=0
=(\lambda-1)(p\lambda-q).
$$
The root in $(0,1)$ is therefore
$$
\boxed{\lambda=\frac{1-p}{p}.}
$$