GeeksforGeeks » Interview Questions
Amazon Interview Question for Software Engineer/Developer (0 - 2 Years) about Algorithms
(2 posts)-
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression
-
Assumptions
1. There is no escape sequence , no parenthesis
2. No input pattern would have consecutive ? *Stack data structures can be used with two variable
1) Current input string index
2) Current symbol to be matched.Compare two symbols one on stack and other as current indexed input character. If matched, increment/push else, push operation.
? will clear up the last pushed character if its not matching the current input character.
* will increment the current input string index until comparison failed.
If stack is not empty return false;
else return true;
Reply
You must log in to post.