(BELOW YOU CAN FIND ATTACHED THE IMAGE OF THE SITUATION)
Answer:

Explanation:
For this we're going to use conservation of mechanical energy because there are nor dissipative forces as friction. So, the change on mechanical energy (E) should be zero, that means:
(1)
With
the initial kinetic energy,
the initial potential energy,
the final kinetic energy and
the final potential energy. Note that initialy the masses are at rest so
, when they are released the block 2 moves downward because m2>m1 and finally when the mass 2 reaches its maximum displacement the blocks will be instantly at rest so
. So, equation (1) becomes:
(2)
At initial moment all the potential energy is gravitational because the spring is not stretched so
and at final moment we have potential gravitational energy and potential elastic energy so
, using this on (2)
(3)
Additional if we define the cero of potential gravitational energy as sketched on the figure below (See image attached),
and we have by (3) :
(4)
Now when the block 1 moves a distance d upward the block 2 moves downward a distance d too (to maintain a constant length of the rope) and the spring stretches a distance d, so (4) is:

dividing both sides by d


, with k the constant of the spring and g the gravitational acceleration.