initially mass m is held such that spring is in its natural length if mass is slowly released then maximum elongation in the spring is L if mass m is suddenly released then maximum elongation in the spring will be
Here we shall use the law of conservation of energy for the spring system
so,
initial total energy = final total energy
potential energy = kinetic energy + spring elastic energy
now if x be elongation of the spring, then
mgx = (1/2)mv2 + (1/2)kx2
now, maximum elongation corresponds to point where the velocity becomes zero and the spring is about to turn backwards.
So, by putting v = 0 in the above relation we get
mgx = (1/2)kx2
or
the maximum elongation would be
x = 2mg / k