Solution (source code)

= Solution

Let $M(t)=m_0-\alpha t$ be the trolley's remaining <mass>. During $dt$, the expelled mass $-dM$ has ground-frame <velocity> $v+u$. Conservation of <momentum> gives, to first order,
$$
Mv=(M+dM)(v+dv)+(-dM)(v+u),
$$
and hence $M\,dv=u\,dM$. Integration yields the <rocket equation>
$$
v-v_0=u\log\frac{M}{m_0}.
$$
At the stopping time, $M=m_0e^{-v_0/u}$. Therefore the time spent ejecting gas is
$$
\boxed{\frac{m_0}{\alpha}\left(1-e^{-v_0/u}\right)}.
$$