Mean time to absorption in gambler's ruin
Let the mean time to absorption be $\tau_x = \expect_x(T)$.
For $x=1,2,\ldots,a-1$, using the law of total expectation, $$ \begin{align*} \tau_x &= \prob(Y_1=1)\expect(X_T=a|Y_1=1)+\prob(Y_1=-1)\expect(X_T=a|Y_1=-1) \\ &= p(1+\tau_{x+1}) + q(1+\tau_{x-1}) \\ &= 1+p\tau_{x+1} + q\tau_{x-1}. \end{align*} $$ and boundary condition is $$ \tau_0 = 0,\quad \tau_a = 0. $$ Solving (Derivation), $$ \tau_x = \begin{cases} x(a-x),& p=\dfrac12,\\ \dfrac{x}{q-p}-\dfrac{a}{q-p}\dfrac{(q/p)^x - 1}{(q/p)^a-1},& p\neq\dfrac12. \end{cases} $$