Mass of first block =m1
Mass of second block =m2
Velocity given to mass m2=v0
(a) So the velocity of centre of mass
=m2v0+m1×0m1+m2
=m2v0m1+m2
(b) Let x be the maximum elongation in the spring.
So, change in kinetic energy = potential energy stored in spring
12m2v02−12(m1+m2)(m2v0m1+m2)2=12kx2
x=√1k(m2v022−m2v0m1+m2)