Answer:
Initially let n cannonballs with a total mass of m be to the left of the center of mass at L /2 and the mass of the car at L/2
x1 = [-m / (m + M)] * L / 2 is the original position of the CM
x2 = (m (x + L/2) + M x) / (m + M) * L/2 final position of CM with all cannon balls to the right
[-m x - m L / 2 + m x - M x] / (M + m) * L/2
= - ( m L / 2 + M x) / (m + M) * L/2 = Xcm
Check the math, but maximum distance occurs when the cannonballs of mass m move from -L/2 to L/2 and the car of mass M moves from zero to -x