Regular Expression Matching

Hard Solved

Description

Implement regular expression matching with support for . and *.

. Matches any single character. * Matches zero or more of the preceding element.

Examples

Input: s = "aa", p = "a"

Output: false

Input: s = "aa", p = "a*"

Output: true

Input: s = "ab", p = ".*"

Output: true

Input: s = "aab", p = "c*a*b"

Output: true

Note:

Runner expects two lines on stdin: first line is the input string s, second line is the pattern p. Program must print true or false (or True/False for Python) exactly as the final output so it's comparable.

Your Submissions

No submissions yet.

Discuss

Common approaches: recursion + memoization (top-down DP), bottom-up DP. Watch edge cases with '*' matching zero occurrences.

Test Cases

Test Case 1
Test Case 2
Test Case 3
Test Case 4