For the first part, the mass sits at rest on the spring, so it is at the equilibrium position and thus mg = kd
So, d = mg/k
For the second part, I assume the uncompressed spring position is 0. When the mass at rest at the top. Its KE and PE is 0. When the mass at distance D, the question said...