The relative speed is 2 km/minute. That is, assume one of the trains is stationary and the other is travelling at the combined speed of both.
The total distance to be travelled before they completely pass each other is (1/2 + 2/3)km = 7/6 km.
Total time is therefore (7/6)/2 minutes = 7/12 minutes = 7*60/12 seconds = 7*5 seconds = 35 seconds
.