Word Pattern II (Round 1, LC 291 :)
Updated
Problem statement
- 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! 🌷
Function
wordPatternMatch(pattern: String, s: String) → booleanExamples
Example 1
pattern = "abab"s = "redblueredblue"return = trueOne possible mapping is as follows:
- 'a' -> "red"
- 'b' -> "blue"
Example 2
pattern = "aaaa"s = "asdasdasdasd"return = trueOne possible mapping is as follows:
- 'a' -> "asd"
Example 3
pattern = "aabb"s = "xyzabcxyzabc"return = falseNo possible mapping exists that can satisfy the given pattern and string.
Constraints
1 <= pattern.length, s.length <= 20patternandsconsist of only lowercase English letters.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- All Long Subsequences Are Dictionary WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Generate Palindromic PermutationsMotive · ONSITE INTERVIEWMotive interview questions
- Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Maximum Unique Substring SplitThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Word Break IIWex · PHONE SCREEN
- Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
- Highest Bid Campaign MatcherStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)