I am facing wrong answers for some testcases.
kindly have a look.
Wrong answer error
Your code is not working for the testcases like:
aa
a*?a
Expected Output:
0
Your Output:
1
a
a*?a
Expected Output:
0
Your Output:
1
a
a*a
Expected Output:
0
Your Output:
1
Can you tell me about the approach for this question. The problem I am facing is that -
As I am using the same 2D grid as in the LCS question ( with changes applied accordingly ) so when s1 = " aa " and s2 = " a*?d " then how will I indicate in the matrix that if ‘d’ has come then automatically something is reflected in the grid and the conclusion can be drawn.
@mananaroramail,
Really sorry for the late update:
Case 1: The character is ‘*’ Here two cases arise
We can ignore ‘’ character and move to next character in the Pattern. ‘’ character matches with one or more characters in Text. Here we will move to next character in the string.
Case 2: The character is ‘?’ We can ignore current character in Text and move to next character in the Pattern and Text.
Case 3: The character is not a wildcard character If current character in Text matches with current character in Pattern, we move to next character in the Pattern and Text. If they do not match, wildcard pattern and Text do not match.
We can use Dynamic Programming to solve this problem – Let T[i][j] is true if first i characters in given string matches the first j characters of pattern.
I have corrected the code here: https://ide.codingblocks.com/s/189078
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.