Artificial intelligent assistant

Biking uphill and downhill During an interview, I was asked "If you can bike 20 mph uphill and 30mph downhill, and you have 1 hour to bike, how far or how long should you ride uphill before turning back." While a very elementary and silly question, no clever solution came to my head at the moment. Using brute force, I approximated the solution but I was hoping someone could help with this and the more general question of "If you can bike X mph uphill and Y mph downhill, and you have Z hour to bike, how far or how long should you ride uphill before turning back." Thanks.

Distance while traveling uphill and downhill is same. Let it be $d$ miles.

$\mathrm{Speed = }\dfrac{\mathrm{Distance}}{\mathrm{Time}}$

Time required to travel uphill will be $t_1 = \dfrac{d}{X}$ hrs.

Time required to travel downhill will be $t_2 = \dfrac{d}{Y}$ hrs.

Now, $t_1 + t_2 = Z \implies d\left(\dfrac{1}{X} + \dfrac{1}{Y}\right) = Z \implies d = \dfrac{ZXY}{X+Y}$ miles

Plugging in $X= 20, Y = 30, Z = 1$, we get $d = \dfrac{20\times30}{50} = 12$ miles.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ed91fa09d345ebebc66d7b74e7e83a92