words and a template word template. A word fits the template if the template's letters can be swapped for other letters one-to-one so that the template turns into that word: equal letters of the template become equal letters, and different letters become different ones.
For example, "add" fits the template "egg", but "aaa" does not (the distinct e and g would become the same letter), and neither does "abc".
Return every word from words that fits the template, in any order.words=["noon", "deed", "tree", "abba", "moon"], template="otto" → ['noon', 'deed', 'abba']
In "otto" the first and last letters are equal, and the two middle ones are equal to each other but different. "noon", "deed" and "abba" share this shape; "tree" and "moon" repeat letters in other places.
words=["aaa", "abc", "xyx"], template="cat" → ['abc']
All letters of "cat" differ, so only "abc" fits: "aaa" and "xyx" repeat letters.
words=["q", "z"], template="m" → ['q', 'z']
words=["noon", "deed", "tree", "abba", "moon"], template="otto"
['noon', 'deed', 'abba']
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.