Stage 1: From $O$ to the point where the string becomes taut (distance $= a$).
The string is slack throughout this stage, so there is no tension and no elastic potential energy. Only gravity and friction act on $P$.
$$\frac{1}{2}mv_a^2 = mga\sin 30° - \mu mg a\cos 30°$$
$$\frac{1}{2}mv_a^2 = \frac{mga}{2} - \frac{mga\sqrt{3}}{6} = \frac{mga(3 - \sqrt{3})}{6}$$
Since $3 - \sqrt{3} \approx 1.27 > 0$, we have $v_a > 0$, confirming that $P$ is still moving when the string becomes taut.
Stage 2: From $x = a$ to the point of maximum extension at $x = a + e$, where $e$ is the extension of the string beyond its natural length.
Write the overall energy balance from $O$ to $a + e$:
$$\underbrace{0}_{\text{Initial KE}} = \underbrace{(-mg(a+e)\sin 30°)}_{\text{Final GPE}} + \underbrace{\frac{\lambda e^2}{2a}}_{\text{Final EPE}} + \underbrace{\mu mg(a+e)\cos 30°}_{\text{Friction loss}}$$
Rearranging: $mg(a+e)\sin 30° - \mu mg(a+e)\cos 30° = \dfrac{\lambda e^2}{2a}$
$$\frac{(a+e)(3-\sqrt{3})}{6} = \frac{e^2}{a}$$
This gives the quadratic equation $6e^2 - a(3-\sqrt{3})e - a^2(3-\sqrt{3}) = 0$.
The discriminant is $\Delta = a^2(3-\sqrt{3})^2 + 24a^2(3-\sqrt{3}) = a^2(84 - 30\sqrt{3})$.
Noting that $84 - 30\sqrt{3} = (5\sqrt{3}-3)^2$, we have $\sqrt{\Delta} = a(5\sqrt{3}-3)$.
$$e = \frac{a(3-\sqrt{3}) + a(5\sqrt{3}-3)}{12} = \frac{4a\sqrt{3}}{12} = \frac{a\sqrt{3}}{3}$$
Total distance from $O$:
$$a + e = a + \frac{a\sqrt{3}}{3} = \frac{a(3+\sqrt{3})}{3}$$