Approach hintTry it first, then revealHide
Record the last occurrence of each letter. Scan while extending the current part's end to the furthest last occurrence seen so far, and close the part when the index reaches that end.
Record the last occurrence of each letter. Scan while extending the current part's end to the furthest last occurrence seen so far, and close the part when the index reaches that end.