This problem is about equations.
The first car have the next equation for your distance from math city:

where d is the distance and h is our unknown value.
And for the second car the equation for distance is:

So, we want to know the value of h which make d equal value for both cars. That's mean:

Now, we isolate h from the equation above:

The answer is h=4 hours.