JAVA | DP + MEMOIZATION | Video Explanation
\nclass Solution {\n    // global dp array \n    Boolean dp[][];\n    \n    boolean wm(String s , String p , int i , int j){\n        // if we reach end of both
```\nclass Solution {\n    // global dp array \n    Boolean dp[][];\n    \n    boolean wm(String s , String p , int i , int j){\n        // if we reach end of both string simultaneously return true\n        if(s.length()==i && p.length() == j) return true;\n        \n        \n        //if string s has ended we need to check that remaining characters in p are all asteriks.\n        if(i == s.length()){\n            for(int index = j;index<p.length();index++){\n                if(p.charAt(index)!=\'*\'){\n                    return false;\n                }\n            }\n            return true;\n        }\n        \n        //if string p has ended and s still remains , there is no way to match, think think!\n        if(j == p.length() && i!=s.length())return false;\n        \n        //if sub problem already solved return it\n        if(dp[i][j]!=null)return dp[i][j];\n        \n        boolean ans = false;\n        \n        if(p.charAt(j)==\'?\'){\n            //using ? as a single character(go ahead in both s and p )\n            if(wm(s,p,i+1,j+1)){\n                ans = true;\n            }\n          \n        }\n        else if(p.charAt(j)==\'*\'){\n            //using * as empty string (go ahead in just p)\n            if(wm(s,p,i,j+1)){\n                ans = true;\n            }      \n            //using * as multiple characters(go ahead in s but not p)\n             if(wm(s,p,i+1,j)){\n                ans = true;\n            }\n            // using * as single character(go ahead in both s and p)\n             if(wm(s,p,i+1,j+1)){\n                ans   = true;\n            }\n            \n        }\n        //if both i and j have characters then if they match go ahead in both else ans is false by default\n        else if(p.charAt(j)==s.charAt(i) && wm(s,p,i+1,j+1)){\n                ans= true;\n        }\n        dp[i][j] = ans;\n        return ans;\n    }\n    public boolean isMatch(String s, String p) {\n        dp = new Boolean[s.length()][p.length()];\n        return wm (s , p , 0 , 0);\n    }\n}\n```\nVideo Explanation:\nhttps://www.youtube.com/watch?v=x4TG1x0STNE
['Dynamic Programming', 'Memoization', 'Java']