Regular Expression Matching

Hard
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Regular Expression Matching

Approach

Build DP over string/pattern prefixes. Handle normal char or dot with diagonal transition, and star with either zero-occurrence or consume-one-character transitions.

Complexity Analysis

Time
O(m * n)
Space
O(m * n)

Pattern

2D Dynamic Programming

Why It Works

Each pattern operator defines deterministic transitions from smaller prefix states, making full-match validity a DP reachability problem.

Updated Feb 2026