✅| C++| 0 ms | Two Pointer | Very Easy.
Left   : keeps track of  (\nRight : keeps track of )\n\nFor First Pass if Right>Left happens then they are re-initialized to zero as  \')\' can\'t come before \
*Left*   : keeps track of  (\n*Right* : keeps track of )\n\nFor First Pass if *Right>Left* happens then they are re-initialized to zero as  \')\' can\'t come before \'(\'\nSimilary,For Second Pass *Left>Right* happens then they are re-initialized to zero as \'(\' should come before \')\'\n\n\n\n```\nclass Solution {\npublic:\n    int longestValidParentheses(string s)\n    {\n        \n        int n=s.size();\n        int ans=0;\n        int left=0,right=0;\n        for(int i=0;i<n;i++)\n        {\n           if(s[i]==\')\')\n           {\n               right++;\n           }\n           else if(s[i]==\'(\')\n            {\n                left++;\n            }\n            if(left==right)\n            {\n                ans=max(left+right,ans);\n            }\n            else if(right>left)\n            {\n                left=right=0;\n            }\n        }\n        \n        left=right=0;\n        \n        for(int i=n-1;i>=0;i--)\n        {\n           if(s[i]==\'(\')\n           {\n               left++;\n           }\n            else if(s[i]==\')\')\n            {\n                right++;\n            }\n            if(left==right)\n            {\n                ans=max(left+right,ans);\n            }\n            else if(left>right)\n            {\n                left=right=0;\n            }\n        }\n        \n        return ans;\n    }\n};\n```\n
['C']