Duval’s algorithm and Lyndon words

Imagine letters around a bracelet. Turn it and you can start reading at any letter. Find the spelling that comes first in a dictionary so the same bracelet can be recognized after any turn.

A Lyndon word is strictly smaller than each of its nonempty proper suffixes. Three pointers identify each factor. For the minimum rotation, scan circularly and skip starting points already ruled out.