"A ball $m$ moves horizontally with velocity $v_0$, colliding with a spring $k$ fixed to a block mass $M$ such as shown in the diagram. The block $M$ has no friction with the ground. What is the maximum compression of the spring?"
This problem came up two times in this course: the first time in an exam in 2014, and now as part of our homework in 2020. However, the problem was solved differently by two different professors and I wish to understand what would be the correct way to look at it since the results are different.
In both solutions it is used conservation of mechanical energy, but the first solution considers the movement of both the block $m$ and $M$ after the "collision" with the spring, writing the following equation for the conservation of mechanical energy:
$$\frac{1}{2}mv_0^2 = \frac{1}{2}(m+M)v^2 + \frac{1}{2}k(\Delta x)^2$$
where $v$ is the final velocity of the system $m + M$ (and $v = \frac{m}{m + M}v_0$ by conservation of linear momentum) and $\Delta x$ the maximum compression value for the spring.
The second solution, however, is different, because it doesn't take into account the kinetic energy for the movement of the system $m + M$ after the collision.
$$\frac{1}{2}mv_0^2 = \frac{1}{2}k(\Delta x)^2$$
This obviously produces another result for the compression of the spring and only one of them can be correct one. Should I consider or not the kinetic energy after the collision? Which way of looking at it is wrong?