how does light know the fastest path to travel?



I was reading about Fermats’s principal of least time and what I’m getting from it is that light follows the path that takes the least time. This is contradictory to the previous notion that light travels in the straightest path ever, so how exactly does light know which way will be fastest?

In: Physics

The straightest path is the fastest path. Light doesn’t ‘know’ that the straightest path is the fastest path, it just so happens that the straightest path is – in all cases, the fastest path between two points in space.

Light behaves like a wave, so it actually goes down *all* the possible paths with the same endpoints. It doesn’t “know” which will be fastest like electricity doesn’t magically know the path of least resistance.