we will assume that the speed of the first will be "x km/hrs"
Then according to the question :
the speed of the other train = "x+10 km/hrs"
We know that "speed = distance ÷ time"
→ the speed of the first train :
⇒ x = distance/2 (here we are using 2 hours as said in the question)
The distance = 2x
2x will be the distance covered by the first train
For the distance covered by the second train:
(we need to only need to add 10 for the distance covered by first train)
For the length of the tracks :
"distance travelled by first train + distance travelled by second train + distance between them"
2x+2(x+10)+40 = 300km
4x+20+40 = 300km
4x = 300km - 60
4x = 240
x = 240 ÷ 4
x = 60 km/hrs
∴ speed of the first train = 60 km/hrs
→ for the speed of the second train :
⇒ 60+10 = 70 km/hrs
∴ the speed of the second train = 70 km/hrs