If mass of the bars be m1 and m2. Mass m1 be at the left side and m2 be attached to right side of the spring.
force applied on the system = F on m1 in the direction left to the spring.
So, acceleration in the system = a = F/(m1+m2)
This frame is accelerated and thus non inertial frame of reference, and in order to apply Newton's laws of motion we apply a pseudo force (m1a) towards left on the block m1 and m2a towards left to the block m2.
We consider the problem from Center of mass frame. In this frame bars move in opposite directions and come to instantaneous rest at some instant. The elongation of the spring will be minimum and maximum at this instant.
Let bar m1 is displaced by a distance x1 and the bar m2 by x2 from the initial positions.
Applying energy equation in center of mass frame,

T + U = W
ext
Here, Wext = work one by the pseudo forces
U = Potential energy of the spring = k(x1 +x2)2/2

T = Kinetic energy = 0
Wext = m1F(x1+x2)/(m1+m2),
So, k(x1 +x2)2/2 = m1F(x1+x2)/(m1+m2)
or, (x1+x2) = 0 or (x1+x2) = 2m1F/k(m1+m2)
Hence the maximum seperation b/w the bars equals : L + 2m1F/k(m1+m2)
The minimum separation corresponds to zero elongation and is equal to L.
STRETCHING OF SPRING ON FRICTIONLESS PLANE
This can easily be explained as there is accleration in the mass bar m2 as a result of which there is tension in the spring.