Regular expression — Asked in Google, Flipkart and Facebook Interview
Problem Statement :
Given an input string ‘S’ and a pattern ‘P’, implement a regular expression matching with the support of two special characters ‘.’ (dot) and ‘*’(asterisk) where :
‘.’ matches to any single character.
‘*’ matches to zero or more of the preceding element.
Sample Input:
S = aa, P = a*
Sample Output:
true
Explanation of Test Case :
‘*’ means that we can replace zero or more of the preceding element. Hence we can replace it with another ‘a’. So, the given string can be formed with the pattern.
Approach :
Bottom-up DP
Time Complexity — O(N*M)
Space Complexity — O(N*M)