Epic Interview Question

How to find the valid parenthesis in this string.