#C12673. Longest Valid Parentheses Substring
Longest Valid Parentheses Substring
Longest Valid Parentheses Substring
In this problem, you are given a string consisting only of the characters '(' and ')'. Your task is to determine the length of the longest contiguous substring that forms a valid sequence of parentheses. A substring is considered valid if every opening parenthesis '(' is properly closed by a corresponding ')' in the correct order.
Mathematically, if we denote the length of a valid substring as (L), you are required to compute the maximum (L) among all substrings of the input string.
inputFormat
Input is provided on standard input (stdin) as a single line containing only the characters '(' and ')'. There are no extra spaces or characters.
outputFormat
Output the length of the longest valid (well-formed) parentheses substring on standard output (stdout).## sample
(()())
6