template and a string text. The string fits the template if every letter of the template can be assigned a non-empty piece of text so that:
- the same letter always stands for the same piece;
- different letters get different pieces;
- replacing each letter of the template with its piece yields exactly text.
Return true if text fits template, and false otherwise.template="xyx", text="tictactic" → True
x → "tic", y → "tac" gives tic + tac + tic.
template="ab", text="gogo" → True
Four letters split into two pieces as g|ogo, go|go or gog|o. The middle split would give both letters the same piece "go", which is not allowed, but the other two work. The answer is true.
template="aab", text="redbluered" → False
template="xyx", text="tictactic"
True
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.