Do the Words Follow the Letter Pattern?
Updated
Problem statement
words and pattern have the same length, and pattern[i] is a single lowercase letter. Position i pairs the word words[i] with the letter pattern[i].
Return true if the pairs are consistent in both directions: every copy of a word is paired with the same letter, and every copy of a letter is paired with the same word. Otherwise return false.
Function
isPattern(words: String[], pattern: String[]) → booleanExamples
Example 1
words = ["mint","sage","mint","plum"]pattern = ["x","y","x","z"]return = truemint always sits with x, sage with y and plum with z. Every word has one letter and every letter one word, so the answer is true.
Example 2
words = ["sun","sun","moon"]pattern = ["p","q","r"]return = falseEach letter has only one word, but sun sits with p first and with q next. One word cannot stand for two letters, so the answer is false.
Example 3
words = ["oak","elm","ash","elm"]pattern = ["r","s","r","s"]return = falseThe letters look fine on their own, but r is paired with oak and later with ash. One letter cannot stand for two different words, so the answer is false.
Constraints
1 <= words.length == pattern.length <= 50001 <= words[i].length <= 10, and words use only lowercase English letters.- Each
pattern[i]is one lowercase English letter.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Isomorphic StringsRemitly · ONSITE INTERVIEWRemitly interview questions
- Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences