Please read through this completely because at first you will think the answer is wrong!
For two throws the outcomes are HH, HT, TH, TT. Only one of these has two heads, probability is 1/4, assuming equal probabilities for a head and tail.
For three throws the outcomes are HHH, HHT, HTH, HTT, THH, THT, TTH, TTT. Since the coin is only thrown till the second head appears we want HTH, THH only, so the probability is 2/8=1/4.
4 throws: HHHH, HHHT, HHTH, HHTT, HTHH, HTHT, HTTH, HTTT, THHH, THHT, THTH, THTT, TTHH, TTHT, TTTH, TTTT. So of these we are looking for those that end in H and only have one other H: HTTH, THTH, TTHH, probability 3/16.
5 throws: we can eliminate those that end in T and have more than 2 H's. We're left with HTTTH, THTTH, TTHTH, TTTHH. Probability: 4/32=1/8.
To generalise we can see that the number of throws, n, has 2^n outcomes. There are n-1 positions for the first H, so we have p(x=n)=(n-1)/2^n as the probability.
n=2: p(2)=1/4; n=3: p(3)=2/8=1/4; n=4: p(4)=3/16; p(5)=4/32=1/8.
This is not the answer we expect so we need to make a small adjustment. If P is the probability of throwing a head and P≠1/2 necessarily, then we need to bring in the probability of throwing a tail=1-P.
The outcomes don't change but the probability does.
For example, when n=5 we have HTTTH, THTTH, TTHTH, TTTHH.
The probability of each of these is P^2(1-P)^3 and there are 4 of them so the overall probability is 4P^2(1-P)^3.
The general case is (n-1)P^2(1-P)^(n-2). This matches the expected answer.
Now let's work out p(2)=P^2; p(3)=2P^2(1-P); p(4)=3P^2(1-P)^2.
If we put P=1/2 (an unbiased coin) then P=1-P and we arrive at the probabilities we found earlier when the premise was that the probabilities of throwing a head or tail were equal.