Explanation:
In train's rest frame, the speed of photon is
and the proper length of the train is
. The time taken by the photon to cross the train is 
In ground frame, the speed of the photon is given as follows:


The speed of light or photon remains same in every frame of reference.
Now, the speed of train is very less as compared to the speed of photon so that
So that, 
The length contraction in the ground frame is given as follows:


Time taken by the photon to travel the length of the train in ground frame is .