<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p>

<ul>
	<li><code>&#39;?&#39;</code> Matches any single character.</li>
	<li><code>&#39;*&#39;</code> Matches any sequence of characters (including the empty sequence).</li>
</ul>

<p>The matching should cover the <strong>entire</strong> input string (not partial).</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aa&quot;, p = &quot;a&quot;
<strong>Output:</strong> false
<strong>Explanation:</strong> &quot;a&quot; does not match the entire string &quot;aa&quot;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aa&quot;, p = &quot;*&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong>&nbsp;&#39;*&#39; matches any sequence.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;cb&quot;, p = &quot;?a&quot;
<strong>Output:</strong> false
<strong>Explanation:</strong>&nbsp;&#39;?&#39; matches &#39;c&#39;, but the second letter is &#39;a&#39;, which does not match &#39;b&#39;.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= s.length, p.length &lt;= 2000</code></li>
	<li><code>s</code> contains only lowercase English letters.</li>
	<li><code>p</code> contains only lowercase English letters, <code>&#39;?&#39;</code> or <code>&#39;*&#39;</code>.</li>
</ul>

import numpy as np

class Solution:
    def isMatch(self, s: str, p: str) -> bool:
        if (s == p == ""): return True
        elif len(p) > 0 and p == "*" * len(p): return True
        elif (s == "" and p != "") or (s != "" and p == ""): return False
        matching = np.array([[False for _ in range(len(p))] for _ in range(len(s))])

        # matches(i, j) returns true s[0:i] matches p[0:j], inclusive
        def matches(i, j):
            # if p[j] is a letter and matches(i - 1, j - 1), return True
            if p[j] not in "?*" and (p[j] == s[i] and matching[i - 1][j - 1]): return True
            elif p[j] not in "?*": return False

            # if p[j] is a ?
            if p[j] == "?" and matching[i - 1][j - 1]: return True
            elif p[j] == "?" and not matching[i - 1][j - 1]: return False

            # if p[j] is a *
            if p[j] == "*":
                # return true if matching[i - 1][j] is true or if matching[i - 1][j - 1] is true
                return matching[i - 1][j] or matching[i - 1][j - 1] or matching[i][j - 1]
 
            return False

        # fill in the first row of base cases (s[0] matches with p[:col])
        for col in range(len(p)):
            if col == 0 and (p[col] == s[0] or p[col] == "?" or p[col] == "*"): 
                matching[0][col] = True
            else:
                # s[0] matches with p[:col] if:
                # 1.   s[0] matches with p[:col - 1] and p[col] == "*"
                # 2.   s[0] == p[col] and p[:col - 1] == "*" * (col)
                if matching[0][col - 1] and p[col] == "*": matching[0][col] = True
                elif (s[0] == p[col] or p[col] == "?") and p[:col] == "*" * (col): matching[0][col] = True
                else: matching[0][col] = False
        
        # fill in the first column of base cases (s[:row] matches p[0])
        for row in range(1, len(s)):
            matching[row][0] = (p[0] == "*")

        for i in range(1, len(s)):
            for j in range(1, len(p)):
                matching[i][j] = matches(i, j)
        
        print(matching)
        return matching[-1][-1]
        

42254