Arturo O. answered 10/30/19
Experienced Physics Teacher for Physics Tutoring
Maximum compression occurs when all the kinetic energy of the ball is converted to elastic potential energy of the spring.
mv2/2 = kx2/2
x = √(mv2/k) = v √(m/k)
You were given m in kg, v in m/s, and k in N/cm. Convert k to N/m.
k = 5.15 N / (0.01 m) = 515 N/m
Now plug in m, v, and k (in N/m) into the equation above for x, and you are done.