Given a `pattern` and a string `s`, return `true` if `s` **matches** the `pattern`. A string `s` **matches** a `pattern` if there is some **bijective mapping** of single characters to **non-empty** strings such that if each character in `pattern` is replaced by the string it maps to, then the resulting string is `s`. A **bijective mapping** means that no two characters map to the same string, and no character maps to two different strings.
Example 1
Input: pattern = abab, s = redblueredblue
Output: true
Explanation: a→red, b→blue reproduces the string.
Example 2
Input: pattern = aaaa, s = asdasdasdasd
Output: true
Explanation: a→asd repeated four times.
Example 3
Input: pattern = aabb, s = xyzabcxzyabc
Output: false
Explanation: No consistent bijection exists.
Try to assign each pattern character a non-empty substring of s. Keep a map char->word and a set of used words to enforce bijection. When a character is already mapped, the next chunk of s must equal its word; otherwise try every prefix as its word and recurse.
Run checks all cases above. Submit evaluates all test cases.