let the length of the trains be 'l' each., velocity of the passenger train be 'v' and the velocity of the freight train be 'v1'
when the passenger train and the freight train are travelling in the opposite directions, then the relative velocity of the passenger train with respect to the freight train(i.e, the velocity of the passenger train as observed by a man sitting in the freight train) =v+v1
and the distance which the passenger train covers to pass the freight train is 'l'+'l' =2l
so time taken =t = 2l/(v+v1)
whent he trains are travelling in the same direction, then the realtive velocity of the passenger train is
again the length is=2l (to overtake the freight train)
so time taken now is= t1 = 2l/(v-v1)
as given in the question, t1 = 2*(t)
so, 2*2l/(v+v1) = 2l/(v-v1)
so, v+v1 =2(v-v1)
so, v= 3*v1
so the passenger train is 3 times faster than the freight train.
hope you know relative velocity.