Skip to content
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

[FEATURE REQUEST] <Wildcard Matching> #4391

Closed
janmeshjs opened this issue Sep 21, 2023 · 3 comments
Closed

[FEATURE REQUEST] <Wildcard Matching> #4391

janmeshjs opened this issue Sep 21, 2023 · 3 comments
Assignees

Comments

@janmeshjs
Copy link
Contributor

What would you like to Propose?

Wildcard Matching Algorithm is one of the most commonly seen algorithms while handling Strings with Dynamic Programming.

It is a string-matching problem where one can check if a given string matches a pattern that contains wildcards. Common wildcards include '*' (matches any sequence of characters) and '?' (matches any single character).
For example:

string1= "hello", string2 = "hllo"
"hello" and "h
llo" match because * can match any characters, so it matches "e"

string1= "programming", string2 = "pr*?aing"
"programming" and "pr
?a*ing" match because * can match "ogramm" and ? can match "o"

string1= "xyz", string2 = "*abc"
"xyz" and "*abc" do not match because * does not match different characters, and there is no matching character after *.

Issue details

The algorithm for the above mentioned Wildcard Matching is mentioned below:

We start with creating a 2D boolean array where dp[i][j] represents whether the first i characters in the pattern match the first j characters in the string.

  • Initialize dp[0][0] to true because an empty pattern matches an empty string.
  • If the pattern has '*', then it can match either:
  • An empty string, in which case dp[i][j] = dp[i-1][j].
  • Any character, in which case dp[i][j] = dp[i][j-1].
  • For '?', it matches if the previous characters matched, so dp[i][j] = dp[i-1][j-1].
  • For non-wildcard characters, they match only if the current characters match, so dp[i][j] = dp[i-1][j-1] && (pattern.charAt(i-1) == string.charAt(j-1)).

I've the code with the test cases ready. Assign me the issue to submit a pr.

Additional Information

No response

@Thanush19
Copy link

I can give efficient solution.. can u assign me @janmeshjs ??

@MadhurGupta979
Copy link

Hi @janmeshjs , I am a active leetcoder and i can provide the efficient solution for this problem with proper comments. Please Assign me this problem as i want to make a contribution.

@shaktimaan00
Copy link

Hi @janmeshjs , I have 3 years programming experience and still active at various coding platforms. I can provide a effective solution with clean comments. Please assign me this problem.

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

No branches or pull requests

4 participants