Denote the entire trip as 2L, so that it travels at 40 m/s for a distance of L and then at 60 m/s for another distance L. The time for the first L travelled is L/40 (time = displacement/velocity) and the time for the second L is L/60.
From this, you have that the total time for the trip is L/40+L/60 and the total distance being 2L, so just divide the distance by the time to find velocity.
Average velocity= total distance/total time
I'll work out the algebra bc I'm bored
V =(2L)/(L/40+L/60)
=(2L)/(3L/120+2L/120)
= (2L)/(5L/120)
= 240L/5L
= 48 m/s