The easiest way to solve this problem is to consider the conservation of energy (assuming no energy is lost in the system). The initial energy that is put into the spring is calculated as Us = 1/2kx2 where Us is the potential energy put into the spring, "k" is the spring constant and "x" is the amount the spring is compressed. To ensure we don't get goofed up in our units, let's convert to SI units so we'll use 0.20 meters for the spring compression.
Us = 1/2(50)(0.20)2 = 1 joule
That means when the pellet reaches its maximum height, it would also have 1 joule of energy, but all of it would be converted to gravitational potential energy which is defined by: Ug = mgh where Ug is gravitational potential energy, m is the mass of the pellet, g = 9.81 m/s2, and "h" is the height (in meters)
So, since Us = Ug, we can say 1 joule = mgh or h = 1/(0.25•9.81) = 0.41 m = 41 cm
For B), consider that the energy at the end of the gun has both kinetic energy and potential energy. The amount of potential energy will be mgh where h = 20cm or 0.20 m so Ug = (0.25)(9.81)(0.20) = 0.4905 joules. Since there is a total of 1 joule in the system, that leaves 1 - 0.4905 or 0.5095 joules for the kinetic energy. Since UK = 1/2mv2, where Uk is kinetic energy, m is the mass of the pellet, and v is the velocity of the pellet. So we can say 0.5095 = 1/2(0.25)v2 or v2 = 4.076 or v = 2.0 m/s