Hello
The total momentum must conserve before and after the collision.
1) Calling

and

the masses of the two carts, and

and

the velocities of the two carts before the collision, the initial momentum is

where the negative sign means the two carts are moving into opposite directions.
2) The two carts after collision are at rest, this means the total momentum after collision is

3) Since the momentum must be conserved, we can write

and substituting

from which we can get the velocity of the second cart: