Simply use conservation of energy
The initial energy is purely kinetic: 0.5mv2
When the spring is compressed to the max, the energy is purely potential: 0.5kx2
When the spring is partially compressed, the energy is a mixture of both: 0.5mv2+0.5kx2
Since the energy is a constant at every step of the way, you can equate the initial energy to the maximum potential energy and isolate x to find the maximum compression, then, for a known compression, you can equate the total energy to the third equation I wrote and isolate the final velocity