Problem 3863 · Medium

Minimum Operations to Sort a String

One operation sorts any substring shorter than the whole string into alphabetical order. Find the fewest operations that sort the string, or -1 if that is impossible.

Open the interactive visualisation