Let the maximum compression in the spring be x. The reference level for potential energy is assumed at the position of maximum compression.
Applying mechanical energy conservation, `DeltaK+DeltaU=0`
As block is released from rest and finally comes to rest. Hence, net change in kinetic energy, `DeltaK=0`.
Net change in potential energy,
`DeltaU=DeltaU_(gr)+DeltaU_(sp)=[-mg(x+h)]+(1/2kx^2)`
`0+[-mg(h+x)]+(1/2kx^2-0)=0`
`x^2-2((mg)/(k))x-2((mg)/(k))h=0`
After solving, we get `x=(mg)/(k)[1+sqrt(1+(2kh)/(mg))]`