Given,
Mass of each block, MA = MB = 2 kg
Initial velocities of block A, Va = 1 m/s
Initial velocity of block B, Vb = 0
Spring constant of the spring = 100 N/m
Block A strikes the spring with a velocity of 1 m/s.
After the collision, it's velocity decreases continuously. At an instant the whole system (Block A + the compound spring + Block B) moves together with a common velocity V (say).
Using the law of conservation of energy, we get:
(where x is the maximum compression of the spring)
⇒ 1 − 2v2 = 50x2 ...(1)
As there is no external force acting in the horizontal direction, the momentum is conserved.