exactly right, think of the problem setup as two sub cases. since there are no dissaptive forces in the problem then all the potential energy will be converted to kinetic energy, if we take our zero for the potential at the level of the spring. so this is the first part. now treat this as the initial condition for the second part, so the particle now has the total kinetic energy and use the energy theorem again to assume that the total kinetic goes into potential for compressing the spring. hope this helps, sincerely, x

so the total potential enegy mgh is=kx. but I don't understand that, as the question does not give any values how do I answer the question?. If I was to solve for x the equation would read as x=mgh/k. So o I just state that the compression is equall to the mgh/k or is there another method for answering this. Thanks!

you're on the right path for the trip down, assuming the particle starts at rest then we have
[tex] T_{f}^{part1} = U_{i}^{part1}\Rightarrow T_{f}^{part1} = mg (H-h) [/tex]
now
[tex]T_{f}^{part1}= T_{i}^{part2} = U_{f}^{part2}-U_{i}^{part2} \Rightarrow mg(H-h)=\frac{k}{2} x^{2} - m g h [/tex]
and solve for [tex] x [/tex]
Note that you may of course set the potential of at h to zero and initially and you get the same answer.
[tex] mgH=\frac{k}{2} x^{2} [/tex]
either way.

So just to be clear, T(f) is the final kinetic energy and U(i) is the initial potential energy. Is that correct?

Yeah, the gravitational potential energy is completely converted into mechanical kinetic energy for the first part of problem so
[tex] T=KE=\frac{m}{2}v^{2}=U=mgH-h\Rightarrow T_{f}=U_{i} \Rightarrow T_{f} =m g H [/tex] where we take the height at [tex] h [/tex] the zero for the potential energy. Now for the second part we assume the particle hitting the spring has the initial kinetic energy from the final kinetic energy of the first part of problem -- note, it is this kinetic energy that will go into compressing the spring, which we assume all the kinetic energy is again converted into potential, but this time the potential is in the compression of the spring. So
[tex] U_{spring} = T_{i}^{part2}=T_{f}^{part1}=U_{grav}^{part1}\Rightarrow
\frac{k}{2}x^{2} = m g H\Rightarrow x=\sqrt{\frac{2mgH}{k}} [/tex]