By mechanical energy conservation between compression positions x and 2x
21kx2=21k(2x)2+21mv2
21kx2−21k4x2=21mv2
21kx2(43)=21mv2
v=4m3kx2=m3k2x
On collision with a block at rest
∵ Velocities are exchanged ⇒ elastic collision between identical masses.
∴v=3=m3k2x
⇒6=m3kx
⇒x=63km
∴ The initial energy of the spring is
U=21kx2=21k×363km=6m
U=6×0.1=0.6J