You are given a coin, which when tossed lands on H (heads) with probability $p$ and T (tails) with probability $1-p$. What is the expected number of flips that you must do before you get $L$ consecutive H?
I am aware how to solve the problem when $L$ is fixed. Let $X$ denote the number of needed flips. Then the answer is $E[X] = \frac{1 - p^L}{p^L(1 - p)}$ (an example derivation is shown here).
What about when $L$ is a random variable with a known distribution? I tried applying the same method as when $L$ is fixed but I can't wrap my head around it because in that case the probability for scoring $L$ consecutive heads is namely $p^L$ which is also a random variable. Do I need simply to work with $E[L]$ when calculating $E[X]$? And if yes, then why?