Key Idea: Potential energy of block at height h is converted into potential energy of spring. When block is at height h, it has potential energy $ mgh, $ which is converted into potential energy of spring to conserve energy i.e., $ mgh=\frac{1}{2}k\,{{x}^{2}} $ where k is force constant of spring.