Camelcase Matching
Expert Answer & Key Takeaways
A complete guide to understanding and implementing Trie.
Camelcase Matching
A query word matches a given
pattern if we can insert lowercase letters to the pattern so that it equals the query. Return a list of booleans.Visual Representation
Queries: ["FooBar", "FooBarTest", "FootBall"]
Pattern: "FB"
"FooBar" -> F-oo-B-ar -> Matches!
"FooBarTest" -> F-oo-B-ar-T-est -> Extra 'T' (Uppercase) -> Fails!Examples
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"
Output: [true,false,true,true,false]
Approach 1
Level I: Two Pointers (Standard Search)
Intuition
For each word, use two pointers to check if the
pattern is a subsequence. Additionally, ensure that any uppercase letters in the word that are NOT in the pattern cause a mismatch.⏱ O(N * L) where N is words, L is word length.💾 O(1)
Approach 2
Level III: Two Pointers / Trie
Intuition
For each query, use two pointers ( for query, for pattern). If , increment both. If is lowercase, increment only . If is uppercase and doesn't match , it's a mismatch. After the loop, if reached pattern length and no extra uppercase letters remain in query, it's a match.
⏱ O(N * L).💾 O(1) extra space.
Course4All Technical Board
Verified ExpertSenior Software Engineers & Algorithmic Experts
Our DSA content is authored and reviewed by engineers from top tech firms to ensure optimal time and space complexity analysis.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.