# Spring and energy problem

Assume h is measured from the top of the spring, then the total vertical displacement is h+d. The change of gravitational potential energy is then mg(h+d). When it stopped by the spring, the potential energy in the spring is equal to mg(h+d). Therefore, we have $mg(h+d)=\frac 12 kd^2$.  Solve for k.