Answer:
When you stretch or compress a spring you work against the restoring force of the spring. This work is stored as elastic potential energy in the spring. The more you stretch or compress the spring, the more work is done by you and more energy is stored.
This is also evident from the expression of the potential energy ( U ) -
U=(1/2)kx2
Where x is the displacement from the unstretched position of the spring. Greater is the x. more is the energy stored.