Camelcase Matching
Master this topic with zero to advance depth.
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
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.
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.
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.