Find And Replace Pattern
medium
1. Given a list of strings words and a string pattern. 2. Return a list of words[i] that match pattern. You may return the answer in any order. 3. A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word. 4. Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.
Constraints
1. 1 <= pattern.length <= 20 2. 1 <= words.length <= 20 3. words[i].length == pattern.length 4. pattern and words[i] are lowercase English letters.
Format
Input
Input: words = ["mno","rst","rss","bll","lml","aaa"], pattern = "epp" Input : Words = ["p", "e", "c"], pattern = "a" Input : Words = ["abc", "pqr", "tuv"], pattern = "aaa"
Output
Output: ["rss","bll"] Explanation: "rss" matches the pattern because there is a permutation {e -> r, p -> s, ...}. "aaa" does not match the pattern because {e -> a, p -> a, ...} is not a permutation, since e and p map to the same letter. Output : ["p", "e", "c"] Output : [] -> Empty
Example
Sample Input
epp
6
mno
rst
rss
bll
lml
aaa
Sample Output
bll rss