solution for valid parenthesis