AAlgoLab
ALG-H003HardStack

Longest Correct Bracket Segment

The text contains only parentheses. Return the length of the longest contiguous substring that is a properly balanced parenthesis sequence.

Contract

input text: string
return integer

Constraints

  • • Input alphabet is ()

Examples

Example 1
text = "(()"
→ 2
Example 2
text = ")()())"
→ 4

5 judge tests (2 shown above). Target complexity: O(n).