Step 1: Let the common distance of the race be $s$.
Since both cars start from rest with constant acceleration:
\[
s=\frac{1}{2}a_1 t_1^2=\frac{1}{2}a_2 t_2^2
\]
where $t_1$ and $t_2$ are the times taken by cars A and B respectively.
Step 2: Given that car A finishes $t$ seconds earlier:
\[
t_2 - t_1 = t
\]
Step 3: From the distance equation:
\[
a_1 t_1^2 = a_2 t_2^2
\Rightarrow \frac{t_2}{t_1}=\sqrt{\frac{a_1}{a_2}}
\]
Step 4: Write $t_2 = t_1 + t$ and substitute:
\[
\frac{t_1+t}{t_1}=\sqrt{\frac{a_1}{a_2}}
\]
Step 5: Solving gives:
\[
t_1=\frac{t}{\sqrt{\frac{a_1}{a_2}}-1}
\]
Step 6: Final speeds at the finish line:
\[
v_A = a_1 t_1,\quad v_B = a_2 t_2
\]
Step 7: Given $v = v_A - v_B$:
\[
v = a_1 t_1 - a_2(t_1+t)
\]
Substituting $t_1$ and simplifying gives:
\[
v=\sqrt{a_1a_2}\,t
\]