so on average, the car did 40 km or 6 hours, so if it travels at that speed for 6 hours, that means it covers 40 kilometers on every passing hour, that makes it 40 * 6 or 240 kilometers total, that's the whole length of the journey.
on the first hour it was going 35 kmh, since it went on for only 1 hour, it did then 35 kilometers.
for the next two hours it went at 45 kmh, so in 1 hour it did 45 km and on the next it did another 45 km, so on those two hours it covered a total of 90 kilometers.
now, for the 1hr and the 2hr, namely for the first 3 hours the car, has already covered 35 + 90 kilometers of the grand total of 240 kilometers of the journey. What's leftover is then 240 - 125, or 115 kilometers for the next 3 hours, since the journey was 6 hours total.
on average the last 3 hours then, will be 115/3 kmh.