A ray of light travels from the point $A$ to the point $B$ across the border between two materials. At the first material the speed is $v_1$ and at the second it is $v_2$. Show that the journey is achieved at the least possible time when Snell's law: $$\frac{\sin \theta_1}{\sin \theta_2}=\frac{v_1}{v_2}$$ holds.
To show that do we have to use Lagrange multipliers method??
But which function do we want to minimize??

The total travel time, which is the sum of travel times from $A$ to the surface and fromthe surface to $B$. The two part times are obtained as length divided by speed, the two lengths depend on the angles.