Consider the block + the sring as the system. The exterN/Al forces acting on the system are a. the force of gravilty, b. the normal force by the table and c. te force by the wall. None of thes edo any work on this system and hence the total mechanical energy is conserved. If the block mocves a distance x before comming to rest, we have
`1/2 mv^2=1/2kx^2`
or, `x=vsqrt(m/k)`