Let r = rate of B, in km/hr.

So, (r+2) = rate of A in the last 6 km.

Time, t, for A to negotiate that last 6 km,

t = distance/rate = 6/(r+2) hrs

Time, t', for B to negotiate that last 6 km,

t' = 6/r hrs

B is ahead by 4 minutes when A was 6 km from finish. Then A lost by 2 minutes in the race.

That means

t = t' -4min +2min

So,

6/(r+2) = 6/r -2min

6/(r+2) = 6/r -1/30

6/(r+2) = (180 -r)/(30r)

Cross multiply,

6*30r = (r+2)(180 -r)

180r = 180r -r^2 +360 -2r

0 = -r^2 -2r +360

r^2 +2r -360 = 0

By Quadratic formula,

r = {-2 +,-sqrt[2^2 -4(1)(-360)]} / 2(1)

r = 18 km/hr or -20 km/hr.

Hence, the speed of A in the last 6 km was 18 +2 = 20 km/hr ----answer.