Skip to content

Conversation

kokatesaurabh
Copy link

Regular Expression Matching (Dynamic Programming)

Problem:
Implement regular expression matching with support for . and * where:

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

The matching should cover the entire input string.

Solution:

  • Implemented using Dynamic Programming (DP) with memoization to optimize repeated computations.
  • Recursive approach with a Boolean[][] memo array.
  • Handles edge cases and patterns containing * and . efficiently.

Example Test Cases:

Input String Pattern Output Explanation
"aa" "a" false "a" does not match entire string "aa"
"aa" "a*" true '*' means zero or more of preceding element, so "aa" matches
"ab" ".*" true ".*" matches zero or more of any character

Folder Structure:

  • src/main/java/com/thealgorithms/dynamicprogramming/RegularExpressionMatching.java → main algorithm
  • src/test/java/com/thealgorithms/dynamicprogramming/RegularExpressionMatchingTest.java → JUnit test cases

Notes:

  • Demonstrates DP technique, not just a LeetCode problem solution.
  • Includes multiple test cases to validate correctness and edge scenarios.

This section can be added in your PR under Dynamic Programming algorithms or in a dedicated contributions section for new algorithms.

@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.74%. Comparing base (a0b6c52) to head (5b5e024).

Files with missing lines Patch % Lines
.../dynamicprogramming/RegularExpressionMatching.java 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #6624   +/-   ##
=========================================
  Coverage     75.74%   75.74%           
- Complexity     5765     5781   +16     
=========================================
  Files           701      702    +1     
  Lines         19757    19770   +13     
  Branches       3831     3837    +6     
=========================================
+ Hits          14964    14974   +10     
- Misses         4214     4216    +2     
- Partials        579      580    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants