Given a simple random walk with $S_n = \sum_{i = 1}^{n}X_n$ where $X_n$ takes values $+1$ and $-1$ with probabilities $p < \frac{1}{2}$ and $1-p$ respectively. Now $M_n = S_n + (1 - 2p)n$ defines a martingale with respect to {$X_n$}. $T = \inf \{n \geq 0 : X_n = 0 \text{ or } N \}$ where $0$ and $N$ are absorbing states.
I'm facing problems finding $\mathbb{E}[T]$, the expected number of steps to absorption. I know I should apply the optional sampling theorem to $\mathbb{E}[M_T]$ but do not know how to proceed from there.
Let $S_0 = x \in [0,N]$ be the initial value of the random walk. Since $M_n := S_n+(1-2p)n$ is a martingale, the optional stopping theorem shows that the stopped process
$$N_n := S_{n \wedge T} + (1-2p) (n \wedge T)$$
is a martingale; in particular $\mathbb{E}(N_n) = \mathbb{E}(N_0)= x$, i.e.
$$\mathbb{E}(S_{n \wedge T}) = (2p-1) \mathbb{E}(n \wedge T)+x.$$
Since $(S_n)_{n \in \mathbb{N}}$ is a simple random walk, we have $|S_{n \wedge T}| \leq N$ for all $n \in \mathbb{N}$. Using the dominated convergence (DCT) and monotone convergence theorem (MCT) we find
$$\mathbb{E}(S_T) \stackrel{\text{DCT}}{=} \lim_{n \to \infty} \mathbb{E}(S_{n \wedge T}) = x + (2p-1) \lim_{n \to \infty} \mathbb{E}(n \wedge T) \stackrel{\text{MCT}}{=} x+(2p-1)\mathbb{E}(T). \tag{1}$$
It remains to calculate $\mathbb{E}(S_T)$. A straight-forward calculation shows that the process
$$Y_n := r^{S_n}$$
is for $r:=(1-p)/p$ a martingale. Using exactly the same reasoning as above (i.e. optional stopping for $n \wedge T$ and dominated/monotone convergence) we find that $\mathbb{E}(Y_T) = \mathbb{E}(Y_0)=r^x$. Since $$S_T = 0 \cdot 1_{\{S_T=0\}} + N \cdot 1_{\{S_T=N\}} \tag{2}$$ we get
$$\begin{align*} r^x = \mathbb{E}(Y_T) = \mathbb{E}(r^{S_T}) &= r^0 \mathbb{P}(S_T=0) + r^N \mathbb{P}(S_T=N)\\ &= (1-\mathbb{P}(S_T=N)) + r^N \mathbb{P}(S_T=N). \end{align*} $$
Thus,
$$\mathbb{P}(S_T=N) = \frac{r^x-1}{r^N-1}. \tag{3}$$
On the other hand, plugging $(2)$ into $(1)$ shows
$$N \mathbb{P}(S_T=N) = x+ (2p-1) \mathbb{E}(T)$$
and so, by $(3)$,
$$\begin{align*} \mathbb{E}(T) &= \frac{1}{2p-1} (N \mathbb{P}(S_T=N)-x) \\ &= \frac{1}{2p-1} \left( N \frac{r^x-1}{r^N-1} -x \right).\end{align*}$$
Since $r=(1-p)/p$ this can be easily expressed in terms of $p$ and $N$.
Remark: For the second part of my answer, i.e. the calculation of $\mathbb{E}(S_T)$, it is crucial that $p \neq 1/2$ (which is equivalent to saying $r \neq 1$).