For equilibrium of block hung from string, Spring force + Buoyant force $=$ Weight of block
So, we have
$k x_1+\rho_1 V g=\rho V g\quad \dots(i)$
$\text { and }$ $k x_2+\rho_2 V g=\rho V g \quad \dots(ii)$
Eliminating $k$, we get
$\rho=\frac{\rho_1 x_2-\rho_2 x_1}{x_2-x_1}$


(The coefficient of viscosity of water is $9.8 \times 10^{-6}$ $\left.\mathrm{N} \mathrm{s} / \mathrm{m}^2\right)$
