Solution (source code)

= Solution

There are no visits when the initial excursion returns to $i$ before hitting $j$, so
$$
\boxed{\mathbb P_i(N=0)=1-\alpha}.
$$
For $k\geq1$, the chain must first hit $j$, return to $j$ before $i$ exactly $k-1$ times, and then hit $i$ before another return to $j$. The <Strong Markov property> gives
$$
\boxed{
\mathbb P_i(N=k)=\alpha^2(1-\alpha)^{k-1},
\qquad k\geq1}.
$$
The formula also covers the boundary cases $\alpha=0$ and $\alpha=1$.