Wildcard pattern matching doubt

Hi,
Please give any hint on the question

Hey @vatsal50 have you read the editorial of this problem? It has detailed explanation in it.

While solving a string you will encounter multiple cases, let’s discuss them.

  • Case 1: The character is β€˜*’ Now you will see that Here two cases Will arise

Either We can ignore β€˜ * ’ character and move to next character in the Pattern.
Or β€˜* ’ character matches with one or more characters in Text. In this case we will move to next character of the string.

  • Case 2: if The character is β€˜?’ We can ignore current character in Text and move to next character in the Pattern and Text.

  • Case 3: if 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.

So , dp relation come is

//If current character of each string matches then mark this as however its previous state was
                dp[i][j] = dp[i-1][j-1];
            
 //As β€˜?β€˜can be mapped with all characters , do the same for this as well
                dp[i][j] = dp[i-1][j-1];
            
//As * can be mapped with all strings , mark current state as OR of both previous states
                dp[i][j] = dp[i-1][j] || dp[i][j-1] ; 
            
//Since no matching took place , mark this cell as false
                dp[i][j] = false ;
       

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.