To solve this problem we need to use the equations related to Elastic Potential Energy, which allows us to know the Energy stored in a spring based on its elastic constant and its respective compression. By definition it is described as

Where,
k = Spring constant
x = Displacement
Our values are given as
As we do not know the spring constant but if the energy stored at the compression given then,



In the case of the second compression and understanding that the spring constant is intrinsic to the internal force of the spring, then

Replacing,


Therefore the elastic potential energy in the spring at this elongation is 45J