Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s =
p =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

DP for regex with . and *.

Approach

dp[i][j] = whether s[:i] matches p[:j]. Cases:

  • If p[j-1] is normal/.: must match last char and dp[i-1][j-1].
  • If p[j-1] is *: either use 0 of previous (dp[i][j-2]) or consume one char if previous matches (dp[i-1][j]). Use rolling DP over rows.
Code
Loading...
Complexity
Time: O(|s||p|)
Space: O(|p|)
Solution
Updated: 2026-02-23

Idea

DP for regex with . and *.

Approach

dp[i][j] = whether s[:i] matches p[:j]. Cases:

  • If p[j-1] is normal/.: must match last char and dp[i-1][j-1].
  • If p[j-1] is *: either use 0 of previous (dp[i][j-2]) or consume one char if previous matches (dp[i-1][j]). Use rolling DP over rows.
Code
Loading...
Complexity
Time: O(|s||p|)
Space: O(|p|)