Answer:
K = mg h
Step-by-step explanation:
We will solve this exercise through energy conservation
Initial. Highest point
Em₀ = U = m g (h + x)
Final. When the spring hits
= K + U = K + mg x
Em₀ =

m g (h + x) = K + mgx
mg h (h + x) –mgx = K
K = mg h
We can also solve it with the points
Initial. Spring contact point
Em₀ = K + U = K + m g x
Final. Maximum compression
=
= ½ k x²
Emo =

K + mg x = ½ k x²
K = ½ k x² - mg x