Word Pattern II

Given a pattern of lowercase letters and a string s of lowercase letters with no spaces, decide whether s can be cut into exactly pattern.length consecutive non-empty pieces so that a one-to-one correspondence exists between pattern characters and pieces.

The correspondence must satisfy both directions:

  • The same pattern character always consumes the same piece.
  • Two different pattern characters never consume the same piece.
  • The pieces appear in pattern order and together use all of s.

Return true when at least one such cut exists and false otherwise.

Examples
Input: ["abab","redblueredblue"]
Output: true
Hints

Word Pattern II

Given a `pattern` of lowercase letters and a string `s` of lowercase letters with no spaces, decide whether `s` can be cut into exactly `pattern.length` consecutive non-empty pieces so that a one-to-one correspondence exists between pattern characters and pieces.