Solve tree view and parentheses cleanup | Meta Interview Question