Problem · String

Word Pattern II (Round 1, LC 291 :)

MediumMicrosoftNEW GRADONSITE INTERVIEW
See Microsoft hiring insights

  • 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! 🌷

    Examples
    01 · Example 1
    pattern = "abab"
    s = "redblueredblue"
    return = true
    One possible mapping is as follows:
    • 'a' -> "red"
    • 'b' -> "blue"
    02 · Example 2
    pattern = "aaaa"
    s = "asdasdasdasd"
    return = true
    One possible mapping is as follows:
    • 'a' -> "asd"
    03 · Example 3
    pattern = "aabb"
    s = "xyzabcxyzabc"
    return = false
    No possible mapping exists that can satisfy the given pattern and string.
    Constraints
    • 1 <= pattern.length, s.length <= 20
    • pattern and s consist of only lowercase English letters.
    More Microsoft problems
    drafts saved locally
    public boolean wordPatternMatch(String pattern, String s) {
      // write your code here
    }
    
    pattern"abab"
    s"redblueredblue"
    expectedtrue
    sign in to submit