
For the blocks $A$ and $B$ $FBD$ as shown below
Equations of motion
$a_A=\frac{F}{M}(\text { in }-x \text { direction })$
$a_B=\frac{F}{M}(\text { in }+x \text { direction })$
Relative acceleration, of A w.r.t. B,
$a_{A, B} =a_A-a_B=-\frac{F}{m}-\frac{F}{M}$
$=-F\left(\frac{M+m}{M m}\right) \text { (along }-x \text { direction) }$
Initial relative velocity of Aw.r.t. $B , u _{ AB }= v _0$ using equation $v ^2= u ^2+2 a$
$0= v _0^2-\frac{2 F ( m + M ) S }{ Mm } \Rightarrow S =\frac{ Mmv _0^2}{2 F ( m + M )}$
i.e., Distance moved by A relative to $B$
$S _{ AB }=\frac{ Mmv _0^2}{2 F ( m + M )}$



