The space between the tops of the two walls can be thought of as an inclined plane. Then the problem is to find the minimum speed to cover distance $L$ on a plane inclined at $\theta$ to the horizontal where $L\sin\theta=h_2-h_1$.
The maximum range on an inclined plane is given by $$R=\frac{u^2}{g(1+\sin\theta)}$$ Using $R=L$ we get a minimum launch speed of $u$ given by $$u^2=g(L+h_2-h_1)$$ To obtain speed $u$ at height $h_1$ above the ground the stone must be launched with speed $v$ given by $$v^2=u^2+2gh_1$$ Therefore $$v^2=g(L+h_1+h_2)$$