FunctionRacerProblemsRace

Fit the Capital Pattern

MediumStringsPython, JavaScript, TypeScript, Java, C++

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

words ["FooBar","FootBall","FrameBuffer","ForceFeedBack","fb"]
pattern "FB"
returns [true,true,true,false,false]

FooBar, FootBall and FrameBuffer are FB with lowercase letters inserted; ForceFeedBack has three uppercase letters; fb has no uppercase letter at all.

Example 2

words ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"]
pattern "FoBa"
returns [true,false,true,false,false]

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems