Only the extrusion force can be provided between AB, and there is no force between them at the moment of AB separation, so the separation position should be when the spring is in the original length. At this time, the AB velocity is constant, and the velocity can be obtained by energy method.
After that, B moves at a uniform speed, and A decelerates under the action of the spring. When A is at rest, the extension of the spring, that is, the moving distance of A, can be obtained by energy theorem.
I don't know if it's right, but I hope to correct it.