I'm César Cordero. I was testing these algorithms, and it works well, but in some cases, they will fail. I would treat it as a string, using a stack, because it could works for a compiler, and could be more than parenthesisparentheses, brackets and keys.
Test these cases, and if it works in all cases, you are in good waydoing well: