To be able to solve this problem, you require to know the concept of relative speed. For those who unaware:
What is relative speed? Basically, it is speed of an object relative to another object. For example- Person A is standing still and B is moving at a speed of 5 mph. What is their relative speed to each other? That is right, 5 mph! But if they started to move to opposite directions: A moves at 2 mph and B at 5 mph in opposite directions, they moving away from each other at 7 mph, therefore they relative speed is 7 mph. If they started to move toward each other: A at 2 mph, and B at 5 mph, they are still covering 7 mph. If they are moving in the same direction, say, A at 2 mph and B at 5 mph, they relative speed to each other is 3 mph. Hope it makes sense.
Back to our question. Basically, we need to find the relative speed of train A to B, which is 90, since together they cover 90 kmph. Now we need to convert 90 kmph to meters per second----->25 meters per second
(For those who struggle with conversion problems----->https://gmatclub.com/forum/conversion-problems-175012.html#p1375755 )
Since the lenght of train B is 150m, we need to find the time trains cover this distance------>150/25=6 seconds
Kudos, if it helped)