Parentheses

Ruby

Given a string, determine the highest depth of nested parentheses and return its count. If there is an invalid amount of parentheses, return -1. Use dfs as the method name.

Example:

"(a) (b)" => 1

"(a) (b))" => -1

"((a) (b))" => 2

def dfs(str) end
<