By the definition, the average speed is the total distance traveled divided by the total time spent. In our problem the total distance and the total time consist of the two halves.
Denote the first half of the distance as `L,` then the second half is also `L.` The time spent during the first half is `L/V_1,` where `V_1` is the speed of the first half. The time corresponding to the second half is similarly `L/V_2.`
Thus the average speed is `(L + L)/(L/V_1 + L/V_2) = 2/(1/V_1 + 1/V_2).` It doesn't depend on `L` and numerically is equal to
`2/(1/40+1/60) = 2/((3+2)/120) = (120*2)/5 = 48 (km/h).`
This is the answer. That said, the expression `2/(1/a + 1/b)` is called the harmonic mean of numbers `a` and `b.`