Customer Support: email@example.com
We are listening to your every feedback,
and taking action to constantly improve your learning experience.
If you have any feedback, please use this form:
- If you are a student, email to firstname.lastname@example.org to get special student discount.
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
Input: s = "aa", p = "a"
Explanation: "a" does not match the entire string "aa".
Input: s = "aa", p = "*"
Explanation: '*' matches any sequence.
Input: s = "cb", p = "?a"
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
Input: s = "adceb", p = "*a*b"
Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".
Input: s = "acdcb", p = "a*c?b"
If you have already read the chapter Regular Expression Matching, which is highly recommended that you do, I would suggest you to first try to solve this problem yourself and write down the recurrence relation, and then come back and peruse this chapter, as this would be a good problem solving practice for you and would boost your confidence, especially if you are preparing for a test or interview.
Let's look at the well-commented code below. The comments describe the algorithm:
This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.
The above content is written by:
If you have any feedback, please use this form: https://thealgorists.com/Feedback.
Follow Us On LinkedIn