The potential energy in the spring is given by:
[tex]V = \frac{1}{2} kx^2[/tex]
where k is the spring constant and x is the compression of the spring.
The work done by friction is given by:
[tex]W = \int\limits {\overrightarrow F \cdot} \,\overrightarrow{ds} = F_{friction} s = \mu Ns = \mu mgs[/tex]
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:
[tex] \frac{1}{2} kx^2 = \mu mgs \\ \mu = \frac{kx^2}{2mgs} [/tex]