Aiight, this question is easy.
And both mine and lil genius had something done wrong in the concepts.
I got the answer now and it is ( 2 f(2m1 + m2) / k (m1 + m2) )
The steps are hard to type lol. I'll tell the concept anyway. Obviously, the max extention is not when the accelerations are same. Infact it is max when the velocities are same. Just imagine, both the bodies will initially accelerate in the same direction and then reach the same velocity. Then any difference in velocity will bring the bodies nearer.
So we can imagine the question in two ways :
1) By finding the extention when bodies have the same velocity. Apply energy conservation. This is quite a mess.
Spring force + Kinetic Energy = Work done by the external force
2) By applying pseudo force so that we can consider a frame at the CM of the two bodies. In this frame, we will find both the bodies to move in opposite direction. Max extention is reached when both the bodies stop at reaching maximum elongation. This is a lot more easier.
acm= (2f-f)/(m1 + m2) = f/(m1 + m2)
Acceleration is towards right, so psedo force acts towards left. Consider the pseudo force in the left direction in both masses apart from the forces 2f and f. The force on one mass be F1 and F2 on other mass.
equation is 1/2 k(x1 + x2)2 = F1x1 + F2x2
x1 + x2 is the max extention. Try solving this way and u will get my answer.