Here a proof with only elemental algebra.
Let $v_1,s_1$ be the initial velocity and initial position of the first car, and $v_2,s_2$ those of the second car. The first car accelerate (or decelerate, depending on the particular situation) with a uniform acceleration $a$.
The equation of motion for the first car is:
$$
s=\dfrac{1}{2}at^2+v_1t+s_1
$$
and his velocity is $v=at+v_1$.
For the second car we have
$$
s=v_2t+s_2 \qquad v=v_2 \qquad (constant)
$$
So, the time when the two cars are in the same position is given by:
$$
\dfrac{1}{2}at^2+v_1t+s_1=v_2t+s_2
$$
solving this equation we find:
$$
t=\dfrac{v_2-v_1 \pm \sqrt{(v_1-v_2)^2-2a(s_1-s_2)}}{a}
$$
Note that the discriminant can always be $>0$, choosing a suitable $a$, so the equation has real solutions whatever be the initial velocities and positions.
Only we have to choose the solution with $t>0$ and this depend on initial velocities. Anyway, we are searching the time when the velocity $v=at+v_1$ of the first car is the same $v_2$ of the second, so we pose:
$$
at+v_1=v_2 \Rightarrow v_2-v_1\pm \sqrt{(v_1-v_2)^2-2a(s_1-s_2)}+v_1=v_2
$$
So, simplifing and squaring we find the formula:
$$
(v_1-v_2)^2=2a(s_1-s_2) \Rightarrow a=\dfrac{(v_1-v_2)^2}{2(s_1-s_2)}
$$
that solve the problem.