Find a match, any match. You will be given very simple patterns. But, how fast can you come up with a solution when you are not allowed to use your regexp library? And yes, you might find this in your next interview.
A set of words and a set of patterns. Each word and each pattern is
given in a line by itself. Words and patterns are separated by
#. In patterns, the character period
. matches any
character. The input is terminated by EOF.
Output. For each pattern, write in a single line the pattern, a space, and true if the pattern matches a word or false if it does not. Output patterns in the order you read them.
Have you heard about tries? Use them maybe?
Here is a Ruby implementation.
Want to read more?
I regularly write solutions to programming problems that you may or may not find in technical job interviews. I also love to explain those solutions and answer questions. If you would like to get the latest problem + solution, subscribe to the newsletter or subscribe via RSS. You can also follow me on Twitter, GitHub, and LinkedIn.