static int helper ( int [ ] a ) {
  HashSet < Integer > vis = new HashSet < > ( ) ;
  int left = 0 , right = 0 ;
  int ans = 0 ;
  while ( left < n ) {
    while ( right < n && ! vis . contains ( a [ right ] ) ) vis . add ( a [ right ++ ] ) ;
    if ( right == n ) {
      ans = Math . max ( ans , right - left ) ;
      return ans ;
    }
    ans = Math . max ( ans , right - left ) ;
    while ( left < n && a [ left ] != a [ right ] ) {
      vis . remove ( a [ left ] ) ;
      left ++ ;
    }
    vis . remove ( a [ left ++ ] ) ;
  }
  return ans ;
}

static int helper ( int [ ] a ) { HashSet < Integer > vis = new HashSet < > ( ) ; int left = 0 , right = 0 ; int ans = 0 ; while ( left < n ) { while ( right < n && ! vis . contains ( a [ right ] ) ) vis . add ( a [ right ++ ] ) ; if ( right == n ) { ans = Math . max ( ans , right - left ) ; return ans ; } ans = Math . max ( ans , right - left ) ; while ( left < n && a [ left ] != a [ right ] ) { vis . remove ( a [ left ] ) ; left ++ ; } vis . remove ( a [ left ++ ] ) ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration 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)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (update_expression (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)))))) (return_statement (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)))))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (update_expression (identifier)))))))) (return_statement (identifier))))