By compressing the spring a distance <em>x</em> (in m), you are storing 1/2 <em>k</em> <em>x</em> ² (in J) of potential energy, which is converted completely into kinetic energy 1/2 <em>m v</em> ², where
• <em>k</em> = 40 N/m = spring constant
• <em>m</em> = 10 kg = mass of the ball
• <em>v</em> = 2 m/s = ball's speed (at the moment the spring returns to its equilibrium point)
So we have
1/2 <em>k</em> <em>x</em> ² = 1/2 <em>m</em> <em>v</em> ²
<em>x</em> = √(<em>m</em>/<em>k</em> <em>v</em> ²) = √((10 kg) / (40 N/m) (2 m/s)²) = 1 m