The problem is as follows:
A smooth sphere with negligible friction of $m=100\,g$ is released from $A$. The spring compresses to $10\,cm$. As a result the sphere reaches B, but at this point it is measured the velocity to be zero. Given this conditions. Find the distance in meters between $A$ and $B$. Assume: $K=600\,\frac{N}{m}$ and $g=10\,\frac{m}{s^2}$.
The alternatives are as follows:
$\begin{array}{ll} 1.&\textrm{3 m}\\ 2.&\textrm{4 m}\\ 3.&\textrm{5 m}\\ 4.&\textrm{6 m}\\ 4.&\textrm{10 m}\\ \end{array}$
What I've attempted to do was to establish the conservation of mechanical energy as follows:
$E_p=E_g$
$mgh=\frac{1}{2}kx^2$
Now the problem arises from which length should be used in consideration here?.
What I did was:
$(0.1)(10)(x\sin 37^{\circ})=\frac{1}{2}(600)(10\times10^-2)^2$
Simplifying this expression I obtained:
$x=5\,m.$ Which corresponds to the answer. But I'm not very convinced of my method. Does it exist another way to do this problem?. In this case the height which I'm assuming if counted from point $A$ to point $B$ and not exactly from where the spring is compressed. But does it exist a justification for this?.
Why the compression of the spring is not expressed in the y direction as $10\cos 37^{\circ}$?. I've already attempted that but it did not work.
Can someone help me here please?.

Hint.
$$ \frac 12 K (\Delta x)^2 = (|AB|+\Delta x)m g\sin\theta $$