# What's the logic behind light's following the longest path according to Fermat's Principle? [duplicate]

In our textbook, it's written that light rays will follow the minimum or maximum distance after being reflected from the plane surface and thus the path will be fixed.

At somewhere, I read that light would follow all possible ways. But in this case, the probability of those unlikely paths gets cancelled. Maybe, it could be the selection of nature of Quantum Mechanics says something different but still I don't know.

If we consider point '$$A$$' as the source of light, then at a point '$$O$$' (not mentioned in the following figure), light drops on the mirror and then is reflected towards point '$$B$$'. Then we can possibly notify the whole path as $$AOB$$ = $$s$$

Now Fermat's principle is saying that '$$s$$' would be the maximum or minimum for the light's trajectory showing the equation $$\frac {ds}{dx} = 0$$

It seems a bit confusing to me because all I knew is that light follows the way it takes least time to travel.

So, what's the logic behind the longest way? Can we lead any conclusion anyhow with the term $$\frac {ds}{dx} = 0$$ for defining it?