Check the question. and here is a great soln given by freneid's prof.
Let us consider that F2>F1.now let m1 be displaced to the ryt by x1 and m2 to the ryt by x2.therefore net displacement of m1 wrt m2=x1-x2.this is also the elongation of the spring.so we get the concept that the relative disp. of the 2 blocks is the elongation of the spring.let us denote it by Srel.then dSrel/dt=Vrel of the two blocks.in position of max.elongation the Vrel=0.now consider the fbds of the 2 blocks. T-F1=m1a1. F2-T=m2a2. solving a1 and a2 we get a1=T-F1/m1 a2=F2-T/m2 therefore rel accn.=a2-a1. now write above accn.=VdVrel/dSrel and put T=kSrel....integrate with limtis Srel=0, Vrel=0 and Srel=x,Vrel=0 where x is max elongation.