text **closed** when:
- every letter that occurs in it occurs nowhere else in text, outside this piece;
- the piece is not the whole of text.
You are given a number need. Is it possible to choose need closed pieces that pairwise do not overlap? Return True or False.
When need = 0 the answer is always True.text="xyxpqrzz", need=3 → True
Pieces like "xyx", "p", "q", "r" and "zz" work: their letters appear nowhere else. For instance "xyx", "p" and "q" are three non-overlapping pieces.
text="abba", need=1 → True
The piece "bb" is closed: the letter b occurs only inside it. So one piece can be cut.
text="abab", need=1 → False
Any piece with a or b must contain every copy of both letters, which is the whole string, and that is not allowed.
text consists of lowercase English letterstext="xyxpqrzz", need=3
True
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.