#C10151. Longest Balanced Bracket Substring
Longest Balanced Bracket Substring
Longest Balanced Bracket Substring
Given a string (S) consisting only of the characters '(' and ')', find the length of the longest contiguous substring that forms a valid balanced bracket sequence. A balanced bracket sequence is one where every opening bracket '(' is properly matched with a closing bracket ')'.
For example, in the string "(()))", the longest balanced substring is "(())" which has a length of 4.
inputFormat
Input is provided via standard input (stdin). The input consists of a single line containing the string (S) composed exclusively of the characters '(' and ')'.
outputFormat
Output the length of the longest balanced substring via standard output (stdout).## sample
()
2
</p>