The potential energy in the spring is given by:

where k is the spring constant and x is the compression of the spring.
The work done by friction is given by:

where s is the sliding distance, N the normal force N = mg, m is the mass of the block, g is the gravitational acceleration and μ is the coefficient of dynamic friction.
The work done by friction must be equal to the energy provided by the spring:
