input: Write a python function to find the length of the longest valid parentheses substring.
  assert longest_valid_parentheses("(()") == 2
  assert longest_valid_parentheses(")()())") == 4
  assert longest_valid_parentheses("") == 0
  assert longest_valid_parentheses("()(()") == 2
  assert longest_valid_parentheses("()(()())") == 8
output: def longest_valid_parentheses(s: str) -> int:
      max_len = 0
      stack = [-1]
  
      for i, char in enumerate(s):
          if char == '(':
              stack.append(i)
          else:
              stack.pop()
              if not stack:
                  stack.append(i)
              else:
                  max_len = max(max_len, i - stack[-1])
  
      return max_len