-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Bug Report for https://neetcode.io/problems/valid-parenthesis-string
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
My wrong solution got accepted for this code:
class Solution { public: vector<vector<vector<int>>> dp; bool func(int idx, int open, int closed, string &s) { if(idx==s.length()) { return open==closed; } if(dp[idx][open][closed]!=-1) return dp[idx][open][closed]; if(s[idx]=='(') { return dp[idx][open][closed] = func(idx+1, open+1, closed, s); } if(s[idx]==')') { if(open<=closed) return dp[idx][open][closed] = false; return dp[idx][open][closed] = func(idx+1, open, closed+1, s); } return dp[idx][open][closed] = func(idx+1, open+1, closed, s) || func(idx+1, open, closed+1, s) || func(idx+1, open, closed, s); } bool checkValidString(string s) { int n = s.length(); dp.resize(n, vector<vector<int>>(n, vector<int>(n, -1))); return func(0, 0, 0, s); } };
