Fit the Capital Pattern
pattern is a string of letters, uppercase and lowercase mixed. A word fits the pattern when the pattern can be turned into the word by inserting lowercase letters anywhere, including at either end, possibly none. Uppercase letters can never be inserted, so every uppercase letter of the word must come from the pattern, and the letters of the pattern must appear in the word in the same order.
For every entry of words decide whether it fits pattern and return the list of answers in the same order. For example with pattern = "FB", FooBar and FrameBuffer fit, ForceFeedBack does not (its second F is an extra uppercase letter) and fb does not (the uppercase F and B are missing). An empty words gives an empty list.
Example 1
FooBar, FootBall and FrameBuffer are FB with lowercase letters inserted; ForceFeedBack has three uppercase letters; fb has no uppercase letter at all.
Example 2
FooBar and FootBall can be built from FoBa; FooBarTest has an extra T, FrameBuffer lacks the a after B, and ForceFeedBack has an extra F.
Constraints
0 <= len(words) <= 201 <= len(words[i]) <= 200 <= len(pattern) <= 6- words and
patternhave letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Kth Letter of the Unpacked TextMedium
- Solve for xMedium
- String to IntegerMedium
- Substrings With Every VowelMedium
- Undo the Column ReadMedium
- Valid Decimal LiteralMedium
- Zigzag ConversionMedium
- Every Smallest Bracket RepairHard