Solution (source code)

= Solution

Let $\tau=T_a\wedge T_b$. The walk exits the finite interval $[a,b]$ almost surely, and the stopped martingale $\phi(S_{n\wedge\tau})$ is bounded between $\lambda^b$ and $\lambda^a$. The <optional stopping theorem> and <bounded convergence theorem> give
$$
1=\phi(0)=\mathbb E[\phi(S_\tau)]
=\lambda^a\mathbb P(T_a<T_b)
+\lambda^b\mathbb P(T_b<T_a).
$$
Solving for the first probability gives the <biased gambler's ruin probability>
$$
\boxed{\mathbb P(T_a<T_b)
=\frac{\lambda^b-1}{\lambda^b-\lambda^a}
=\frac{\phi(b)-\phi(0)}{\phi(b)-\phi(a)}.}
$$