Let x be the extension in spring when 2 kg mass leaves contact with the ground.

$kx=2 g$

$x=\large\frac{2g}{k}$

$\quad=\large\frac{2 \times 10}{40}=\frac{1}{2}$$m$

By law of conservation of energy for 5 kg mass

$mgx=\large\frac{1}{2}$$ k^2+\large\frac{1}{2}$$mv^2$

$v= \sqrt {2gx-\large\frac{kx^2}{m}}$

$v=\sqrt {2 \times10 \times \large\frac{1}{2} -\large\frac{40}{5} \times \large\frac{1}{4}}$

$v=2 \sqrt 2 m/s$

Hence b is the correct answer.