Answer
The spring is compressed by a distance of $~~33~cm$
Work Step by Step
We can use conservation of momentum to find the speed $v$ of the two blocks after the collision:
$p_f = p_i$
$(2.0~kg+1.0~kg)~v = (2.0~kg)(4.0~m/s)$
$v = \frac{(2.0~kg)(4.0~m/s)}{3.0~kg}$
$v = 2.67~m/s$
At maximum compression, the spring potential energy in the spring will be equal in magnitude to the kinetic energy of the two blocks immediately after the collision.
We can find the distance $x$ that the spring is compressed:
$\frac{1}{2}kx^2 = \frac{1}{2}mv^2$
$x^2 = \frac{mv^2}{k}$
$x = \sqrt{\frac{mv^2}{k}}$
$x = \sqrt{\frac{(3.0~kg)(2.67~m/s)^2}{200~N/m}}$
$x = 0.33~m$
$x = 33~cm$
The spring is compressed by a distance of $~~33~cm$