static boolean isValid ( char [ ] S , char [ ] variant ) {
  int count = 0 ;
  for ( char c : S ) {
    char bracket = variant [ c - 'A' ] ;
    if ( bracket == ')' ) {
      count -- ;
    }
    else {
      count ++ ;
    }
    if ( count < 0 ) {
      return false ;
    }
  }
  return ( count == 0 ) ;
}

static boolean isValid ( char [ ] S , char [ ] variant ) { int count = 0 ; for ( char c : S ) { char bracket = variant [ c - ' A ' ] ; if ( bracket == ' ) ' ) { count -- ; } else { count ++ ; } if ( count < 0 ) { return false ; } } return ( count == 0 ) ; }
(method_declaration (modifiers) type: (boolean_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (character_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (character_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (update_expression (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (false)))))) (return_statement (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))