Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Word Pattern

XPChallenge Points: 10
levelLevel: Easy

You are given a pattern string and another string s.
Determine whether s follows the same pattern as described below:
• Each character in the pattern corresponds to exactly one unique word in s.
• Each word in s corresponds to exactly one unique character in the pattern.
• There is a one-to-one mapping (bijection) between pattern characters and words.
If such a mapping exists, return true; otherwise, return false.

Example 1:

Input: pattern = "xyyx" s = "apple banana banana apple"

Output: true

Example 2:

Input: pattern = "xyyx" s = "apple banana banana kiwi"

Output: false

Example 3:

Input: pattern = "xxxx" s = "apple banana banana apple"

Output: false

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result