Epic interview question

How to find the valid parenthesis in this string.