Python 3 | O(n) Solution
Algorithm Explanation:\n1. check for the base case and if valid string make stack and add dummy value (reason explained in step )\n2. loop through the string us
Algorithm Explanation:\n1. check for the base case and if valid string make stack and add dummy value (reason explained in step )\n2. loop through the string using enumerate as we will use both character and index of the character to count the longest valid parentheses\n3. we will append open bracker index in stack and pop the last element when closed parentheses encountered\n4.  if we encounter closed parentheses as our first value than we will have dummy value to remove from stack\n5.  after removing last element from the stack check if stack is empty if it is than append index of current character\n6.  if not than we will calculate current length which will be current index - last value of stack\n7.  for max length we will do max of current lengh and assigned max lenght\n```\nclass Solution:\n    def longestValidParentheses(self, s: str) -> int:\n\t\t# base case check\n        if not s:\n            return 0\n        stack = [-1] # \n        max_len = 0\n        for i, ch in enumerate(s):\n            if ch == \'(\':\n                stack.append(i)\n            else:\n                stack.pop()\n                if not stack:\n                    stack.append(i)\n                else:\n                    curr_len = i - stack[len(stack)-1]\n                    max_len = max(curr_len, max_len)\n        return max_len\n```\n\nPlease upvote this solution if you find it helpful.\nany suggestions or imporvement are more than welcome.
['Stack', 'Python', 'Python3']