public static String process ( TestCase testCase ) {
  final int N = testCase . N ;
  final List < String > W = testCase . W ;
  final Set < String > announced = new HashSet < > ( Collections . singletonList ( W . get ( 0 ) ) ) ;
  return IntStream . range ( 1 , N ) . allMatch ( i -> {
    final String prev = W . get ( i - 1 ) ;
    final String curr = W . get ( i ) ;
    final boolean notAnnounced = ! announced . contains ( curr ) ;
    final boolean charSatisfied = curr . charAt ( 0 ) == prev . charAt ( prev . length ( ) - 1 ) ;
    announced . add ( curr ) ;
    return notAnnounced && charSatisfied ;
  }
  ) ? YES : NO ;
}

public static String process ( TestCase testCase ) { final int N = testCase . N ; final List < String > W = testCase . W ; final Set < String > announced = new HashSet < > ( Collections . singletonList ( W . get ( 0 ) ) ) ; return IntStream . range ( 1 , N ) . allMatch ( i -> { final String prev = W . get ( i - 1 ) ; final String curr = W . get ( i ) ; final boolean notAnnounced = ! announced . contains ( curr ) ; final boolean charSatisfied = curr . charAt ( 0 ) == prev . charAt ( prev . length ( ) - 1 ) ; announced . add ( curr ) ; return notAnnounced && charSatisfied ; } ) ? YES : NO ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration (modifiers) type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration (modifiers) type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))))))) (return_statement (ternary_expression condition: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) name: (identifier) arguments: (argument_list (lambda_expression parameters: (identifier) body: (block (local_variable_declaration (modifiers) type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration (modifiers) type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration (modifiers) type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (local_variable_declaration (modifiers) type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (return_statement (binary_expression left: (identifier) right: (identifier))))))) consequence: (identifier) alternative: (identifier)))))