I need some help with determining the equation for this problem. "The block of mass m is released from rest on the frictionless incline. After sliding a certain distance, it compresses a spring and comes to rest at a distance of y beneath its original position. How much energy is stored in the spring?"

I know that it starts with potential energy= Elastic or mgy=kx^2 however I do not know how to manipulate this for the answer. I was thinking perhaps 1/2my^2 or even 1/2mgy but I am not certain how to proceed to answer this question. Thank you in advance.

2 answers

final energy in spring+gain of PE=0
springenergy-mgy=0
solve for spring energy
Doesn't that just give me back my original equation of mgy=kx^2?