My answer is equivalent with the validated answer but my approach is more intuitive- I hope.
First we need to agree that the structure of payments extinguishes the debt. Otherwise said neither part takes advantage of the other in the second scenario of payments.
Now let’s analyze the first structure:
- The residual debt after first payment is $4000(1+i)^{14}-4000$
- The residual debt after second payment is zero: $4000(1+i)^{28}-4000(1+i)^{14}-5440.32=0$
Since the residual debt must be zero, then we could solve for $x=(1+i)^{14}$:
$4000x^2-4000x-5440.32=0, x=\frac{4000+\sqrt{4000^2+4\cdot 4000\cdot 5440.32}}{2\cdot 4000}$
Therefore, $(1+i)^{14}=1.7689\Rightarrow i=4\%$
The debt that in the last 14 years amounts to 5440.32 started at $\frac{5440.32}{(1+i)^{14}}$
Now to extinguish in 7 years a debt which in 14 years would amount to 5440.32 at an interest rate i needs to be paid $\frac{5440.32}{(1+i)^{14}}\cdot (1+i)^7=4090.48$.
Final note: both answers produce the same numerical results. However, there is a mistake: while the borrower might have a reason to extinguish the debt sooner, the lender’s interest is only in revenue from interest on lending. In this light then the lender should charge full 14-years interest even when the borrower obliges to pay sooner. The context of the problem is well presented as borrowing between friends but it would not apply to an institutional lender. The only reason an institutional lender would agree on the terms presented in this problem was if the lender already had another borrower lined and willing to accept terms worse than the actual borrower, otherwise said it would advantage the lender to end the current contract sooner.