I am trying to work through this problem from Sheldon's 10th Ed., 7.61. It states
A coin that comes up heads with probability p is continually flipped. Let N be the number of flips until there have been both at least n heads and at least m tails. Derive an expression for E[N] by conditioning on the number of heads in the first n + m flips.
Following their suggestion, if we let H be the number of heads obtained in the first $n+m$ flips, then $$E[N]=\sum_{j=0}^{n+m} E[N|H=j]P\{H=j\} = \sum_{j=0}^{n+m} E[N|H=j]\binom{n+m}{j}p^j(1-p)^{n+m-j}$$ Clearly, $n+m$ is the minimum number of flips required to obtain n heads and m tails, and if we assume that we have already obtained h heads, then we need $n-h$ more, while we must already have $n+m-h$ tails, so we need $m-(n+m-h)=h-n$ more. However, at that point I am stuck; it seems to me that I have not reduced the complexity of the problem since in obtaining $n-h$ more heads, we may or may not obtain $h-n$ more tails, and vice versa. I have access to the answer, and it states that $$\sum_{j=0}^{n+m} E[N|H=j]\binom{n+m}{j}p^j(1-p)^{n+m-j}=\sum_{j=0}^n \left(n+m+\frac{n-j}{p}\right)\binom{n+m}{j}p^j(1-p)^{n+m-j} + \sum_{j=n+1}^{n+m} \left(n+m+\frac{j-n}{1-p}\right)\binom{n+m}{j}p^j(1-p)^{n+m-j}$$ However, I cannot make the mental leap and see how $E[N|H=j]=\left(n+m+\frac{n-j}{p}\right)$ when $0≤j≤n$ and $E[N|H=j]=\left(n+m+\frac{j-n}{1-p}\right)$ when $n+1≤j≤n+m$.