According to work - mechanical energy theorem ,
W = K(final) - K(initial) + U(final) - U(initial) . . . . (1)
as we define Potential energy as negative of work done by conservative force and assuming that the only force in this situation is Spring force then ,
W(spring) = K(final) -...