79: Longest valid parentheses

Given a string, that contains parentheses, return length of the longest valid sequence

Note: sequence is valid if open bracket has the corresponding close bracket

 

Example 1

Input:  ())(())

Output: 4

Explanation: (()) longest valid sequence

Example 2

Input:  )()()

Output: 4
Difficulty:Hard
Topic:Dynamic programming
Problem #:79