FastPrepFastPrep
Problem Brief

Word Pattern II (Round 1, LC 291 :)

NEW GRADONSITE INTERVIEW

  • Round 1: Word Pattern II 🦭
  • Round 2: Implement Queue using Stacks πŸ¦₯
  • Round 3: Island Perimeter πŸ¦‰
  • 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.

    🌷 wallz carries! 🌷

    1Example 1

    Input
    pattern = "abab", s = "redblueredblue"
    Output
    true
    Explanation
    One possible mapping is as follows:
    • 'a' -> "red"
    • 'b' -> "blue"

    2Example 2

    Input
    pattern = "aaaa", s = "asdasdasdasd"
    Output
    true
    Explanation
    One possible mapping is as follows:
    • 'a' -> "asd"

    3Example 3

    Input
    pattern = "aabb", s = "xyzabcxyzabc"
    Output
    false
    Explanation
    No possible mapping exists that can satisfy the given pattern and string.

    Constraints

    Limits and guarantees your solution can rely on.

    • 1 <= pattern.length, s.length <= 20
    • pattern and s consist of only lowercase English letters.
    public boolean wordPatternMatch(String pattern, String s) {
      // write your code here
    }
    
    Input

    pattern

    "abab"

    s

    "redblueredblue"

    Output

    true

    Sign in to submit your solution.