text **closed** if, for every letter it contains, all other occurrences of that letter in text are inside it too.
Choose as many non-overlapping closed substrings as possible. If several choices reach that count, take the one with the smallest total length; it is always unique.
Return the chosen substrings in any order.text="xyxzwwz" → ['y', 'ww']
The closed pieces are "xyx", "y", "zwwz", "ww" and the whole string. Taking "y" and "ww" gives two disjoint pieces with the smallest total length.
text="abab" → ['abab']
Any piece with an a must also take both bs, so the only closed piece is the whole string.
text="qrrsq" → ['rr', 's']
text consists of lowercase English letterstext="xyxzwwz"
['y', 'ww']
Run checks the first 3 tests in your browser. Submit checks all 62 tests on the server, hidden ones included.