A mass $m_1$ with initial velocity $V_0$ collides with a spring attached to mass $m_2$ initially resting on a frictionless surface according to the figure below. Considering the spring constant $K$ and the negligible mass, do you ask if:
a) Determine the maximum spring compression.
b) If long time after collision both objects travel in the same direction, determine the velocities $V_1$ and $V_2$ of masses $m_1$ and $m_2$ respectively.
$Attemp:$ This is similar to 2017 F=ma Problem 24.
(a) We use conservation of energy and momentum. We have an inelastic collision when the ball hits the block and spring configuration. Since the spring is massless we can write a conservation of momentum equation without worrying too much about the spring yet. $m_1v_1=(m_1+m_2)v’\implies v’=\frac{m_1v_1}{m_1+m_2}$Next we use conservation of energy. We write the equation $$\frac{1}{2}m_1v_1^2=\frac{1}{2}kx^2+\frac{1}{2}(m_1+m_2)v’^2$$ substituting $$v’=\frac{m_1v_1}{m_1+m_2}$$ we get $\frac{1}{2}m_1v_1^2=\frac{1}{2}kx^2+\frac{1}{2}(m_1+m_2)\left(\frac{m_1v_1}{m_1+m_2}\right)^2$ simplifying and multiplying both sides by two we have $m_1v_1^2=kx^2+\frac{m_1^2v_1^2}{m_1+m_2}$ subtracting both sides and simplifying the equation for only $x$ on one side we have $$x=\sqrt{\frac{m_1v_1^2\left(1-\frac{m_1}{m_1+m_2}\right)}{k}}$$ $$x=v_1\sqrt{\frac{m\left(\frac{m_1+m_2}{m_1+m_2}-\frac{m_1}{m_1+m_2}\right)}{k}}$$ $$x=v_1\sqrt{\frac{m_1m_2}{k(m_1+m_2)}}$$
How can I solve a b?

The result for part a is correct, but the reasoning is not perfect, therefore you have questions about part b. So let's describe what is happening. As soon as the object of mass $m_1$ hits the spring, it will start slowing down, and object of mass $m_2$ will start accelerating. At any point after the collision, we call $v_1$ the velocity of mass $m_1$ and $v_2$ will be the velocity of mass $m_2$. You correctly pointed out that momentum is conserved: $$m_1v_0=m_1v_1+m_2v_2$$ As long as $v_1>v_2$ the mass $m_1$ will get closer to $m_2$. Since $v_1$ is decreasing and $v_2$ is increasing, at some point they will have the same velocity $v$. After this point the spring is still compressed, so $m_1$ will still slow down even more and $m_2$ will continue accelerating, but the distance between them is increasing. So the minimum distance is when they have the same velocities. Then your calculations seem correct.
Now what is happening afterwards? Like I've mentioned, $m_1$ will continue slowing down and $m_2$ will continue accelerating, while the spring returns to the original length. At this point there is no more force acting on either objects, so , if the spring does not get stuck to mass $m_1$, they will keep moving with whatever velocities they have at that point. You can still write the same equation for conservation of momentum as above, and you can write the conservation of energy, which will look like the one for elastic collision: $$\frac 12 m_1v_0^2=\frac 12 m_1v_1^2+\frac12m_2v_2^2$$ Notice that the spring is uncompressed, so the elastic energy is still the same as before collision. You now have two equations with two unknowns, which I assume you already know how to solve.
Let me know if something is unclear.