Let $ v \,km \,h^{-1} $ be the constant speed with which the bus travel ply between the towns $ A $ and $ B $ .
Relative velocity of the bus from $ A $ to $ B $ with respect to the cyclist $ = (v - 20) \,km \,h^{-1} $
Relative velocity of the bus from $ B $ to $ A $ with respect to the cyclist $ = (v + 20) \,km\, h^{-1} $
Distance travelled by the bus in time $ T $ (minutes) $ = vT $
As per question
$ \frac{vT}{v-20}=18 $ or $ vT=18v-18\times 2 0 $ and $ \frac{vT}{v+20}=6\quad\ldots\left(i\right) $
or $ vT=6v+20\times6\quad\ldots\left(ii\right) $
Equating $ \left(i\right) $ and $ \left(ii\right) $ , we get
$ =18v-18\times20=6v+20\times 6 $
or $ 12v=20\times6+18\times20=480 $ or $ v=40\,km\,h^{-1} $
Putting this value of $ v $ in $ \left(i\right) $ , we get
$ 40T=18\times40-18\times20=18\times 20 $
or $ T=\frac{18\times20}{40}=9 $ min