ok since no info is given.. i am assuming the collision to be elastic that is...e=1... hence let us consider the initial velocity of the mass m to be u then on collision the velocity of mass 2m will be 2u/3 (by using elastic collision formula).....now mass m is out of the picture...now...since this takes place in a short amount of time(impulsive force) the compression of the spring during this time is negligible...hence the spring goes on getting compressed and at the same time the velocity of the mass 3m goes on increasing till both the masses move with the same velocity...at this moment....there can be no further compression of the spring...(relative velocity of the 2 masses is zero) hence they move as a unit... now we can conserve momentum... initial momentum=4mu/3 final momentum = 5mv where v is final velocity....hence 4mu/3=5mv or v= 4u/15 ------1 ... also conserving energy....1/2 2m (2u/3)2 = 1/2 kx2+1/2 5mv2 ------2 putting 1 in 2 and solving we get xmax= 4sqrt(E/15k) where E is the initial Kinetic energy....hope i didnt make any calculation error...