Solution (source code)

= Solution

From state $i>0$ the chain moves deterministically to $i-1$. From zero it jumps to $j$ when the next lifetime is $j+1$. Thus
$$
p_{i,i-1}=1\ (i>0),\qquad p_{0,j}=q_{j+1}\ (0\le j<N),
$$
with all other probabilities zero.