Answer:
a)

b)

Step-by-step explanation:
Given:
- spring constant,

- kinetic energy of cookie,

- frictional force on the cookie,

a)
Now the kinetic energy here is changing into frictional energy and the spring potential energy.
So, by the law of energy conservation:


where:
distance travelled by the cookie from the unstretched position to the stretched position of the spring.


( neglecting the negative value)
b)
Now, after the compression of the spring there is no kinetic energy for the moment as the velocity of the cookie is zero but there is a spring potential energy due to the compressed spring.
So, here we have the spring potential energy getting converted into kinetic energy and the frictional losses:

where:
U = spring potential energy
KE = kinetic energy
energy lost due to friction

