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"
Output: false
Explanation: "a" does not match the entire string "aa".
Input: s = "aa", p = "*"
Output: true
Explanation: '*' matches any sequence.
Input: s = "cb", p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
0 <= s.length, p.length <= 2000s contains only lowercase English letters.p contains only lowercase English letters, '?' or '*'.The problem of wildcard matching can be thought of in a recursive manner by breaking down the problem into simpler sub-problems. If the current characters match (considering ? matches any single character), we can recursively match the rest of the string. If we encounter a *, we have the choice to ignore it or assume it matches one or more characters. This approach, however, is non-optimal due to potential overlapping sub-problems but provides a good base for understanding.
Memoization optimizes the recursive approach by storing results of previously solved sub-problems, so they are not recomputed. This reduces the time complexity significantly by caching intermediate results.
The dynamic programming solution uses a 2D table where dp[i][j] stores whether the first i characters of the string match the first j characters of the pattern. Use iteration to fill out the DP table based on matching rules and previously computed values. This ensures optimal substructure and overlapping sub-problems are effectively handled.