The distance from A to B is given as d km.
The average speed is calculated using the formula average speed = total distance traveled / total time taken.
The total distance traveled is given as 2d km, which is the distance from A to B plus the distance from B to A.
The total time taken is calculated by adding the time taken to travel from A to B to the time taken to travel from B to A.
The time taken to travel from A to B is given as d/20 hours, and the time taken to travel from B to A is given as d/30 hours.
Plugging the values for total distance traveled and total time taken into the formula for average speed,
we get average speed = (2d km) / [(d/20 hours) + (d/30 hours)].
Simplifying the expression for total time taken, we get average speed = (2d km) / [5d/60 hours].
Finally, we can solve for the average speed by dividing both sides of the equation by 5d/60 hours,
which gives us average speed = (2d km) / (5d/60 hours) = 24 km/hr