Longest Valid Parentheses

Given a string containing just the characters '(' and 'smilie', find the length of the longest valid (well-formed) parentheses substring.
Example
For "(()", the longest valid parentheses substring is "()", which has length = 2.
For ")()())", where the longest valid parentheses substring is "()()", which has length = 4.

Login to see Answer and Coaching Session More interview questions