Consider the two blocks plus the spring to the the system, no external force acts on this suystem in horizontal direction. Hence the linear momentum will remain constant. Suppose, the block of mass `M` moves with a speed `V` and the other block with a speed `v` after losing contact with spring. From conservation of linear momentum in horizontal direction, we have
`MV-mv=0` or `V=(mv)/M`........i
Initially, the mechanical energy of the system `=1/2MV^(2)`
finally the mechanical energy of the system `=1/2mv^(2)+1/2MV^(2)`
As there is no friction, mechaical energy will remain conserved, therefore, `1/2m^(2)+1/2MV^(2)=1/2k^(2)`.........ii
Solving Eqn i and ii, we get
`v=[(kM)/(m(M+m))]^(1/2)x`
and `V=[(kM)/(M(M+m))]^(1/2)x`