I found this question on one of the forum
Regex may contain characters ‘a-z’, ‘.’ and ‘*’ where ‘.’ matches any character and ‘*’ means 0 or more occurrences of the previous character preceding it.
Examples:
1) a*b matches b,ab,aab
2) a.b matches aab, abb, acb,…, azb
3) .* matches all the valid strings formed by using the lowercase letters
Status: Solved
Algorithm:Recursion
Time Complexity O(2^n)
Space Complexity O(1)
Regex may contain characters ‘a-z’, ‘.’ and ‘*’ where ‘.’ matches any character and ‘*’ means 0 or more occurrences of the previous character preceding it.
Examples:
1) a*b matches b,ab,aab
2) a.b matches aab, abb, acb,…, azb
3) .* matches all the valid strings formed by using the lowercase letters
Status: Solved
Algorithm:Recursion
Time Complexity O(2^n)
Space Complexity O(1)
4 comments :
How are you doing it in O(n) without the Deterministic finite automata approach ?
Is there any other approach to do it in O(n) ??
The naive approach is O(2^n) in the worst case
@sankalp do mean using recursion
post your solution i will check it out & then post my solution as well
Shashank
Could you please post the solution in O(n).....
@anon . i don' think it can done in O(N) ?
Post a Comment