Skip to content

Bug Report for regular-expression-matching #4227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ShauryaTomer opened this issue Jun 4, 2025 · 1 comment
Closed

Bug Report for regular-expression-matching #4227

ShauryaTomer opened this issue Jun 4, 2025 · 1 comment

Comments

@ShauryaTomer
Copy link

Bug Report for https://neetcode.io/problems/regular-expression-matching

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

My current solution is accepted on neetcode but it should fail for the following test case s = "a" p = "ab*"

class Solution {
    public static boolean isMatch(String s, String p) {
        return checkMatch(0, 0, s, p);
    }

    public static boolean checkMatch(int indS, int indP, String s, String p) {
        if(indS == s.length() && indP == p.length()) return true;
        if(indS >= s.length() || indP >= p.length()) return false;

        boolean isPossible = false;

        char schar = s.charAt(indS), pchar = p.charAt(indP);
        if(pchar >= 'a' && pchar <= 'z') {
            if(schar == pchar) {
                isPossible = isPossible | checkMatch(indS + 1, indP + 1, s, p);
            } else {
                isPossible = isPossible | checkMatch(indS, indP + 1, s, p);
            }
        } else if(pchar == '.') {
            isPossible = isPossible | checkMatch(indS + 1, indP + 1, s, p);
        } else {
            char prevChar = p.charAt(indP - 1);
            if(prevChar == '.') {
                isPossible = isPossible | checkMatch(indS + 1, indP, s, p) 
                                        | checkMatch(indS + 1, indP + 1, s, p)
                                        | checkMatch(indS, indP + 1, s, p);
            } else {
                if(prevChar == schar) {
                    isPossible = isPossible | checkMatch(indS + 1, indP, s, p) 
                                            | checkMatch(indS + 1, indP + 1, s, p)
                                            | checkMatch(indS, indP + 1, s, p);
                } else {
                    isPossible = isPossible | checkMatch(indS, indP + 1, s, p);
                }
            }
        }

        return isPossible;
    }
}
@Srihari2222
Copy link
Collaborator

Thanks for the feedback! The testcase has been added to the backend and soon will reflect on the site.

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

No branches or pull requests

2 participants