Maximum Number of Non-Overlapping Substrings
Expand each letter’s first-to-last span until it is closed, then choose the non-overlapping spans by earliest right end.
Expand each letter’s first-to-last span until it is closed, then choose the non-overlapping spans by earliest right end.