public static int getMaxRelations ( HashMap < Integer , ArrayList < Integer >> relations , ArrayList < Integer > friends ) {
  int max = 1 ;
  for ( int data : friends ) {
    if ( relations . containsKey ( data ) ) {
      ArrayList < Integer > list = new ArrayList < Integer > ( ) ;
      for ( int temp : relations . get ( data ) ) {
        if ( friends . contains ( temp ) ) {
          list . add ( temp ) ;
        }
      }
      if ( list . size ( ) != 0 ) {
        max = Math . max ( max , 1 + getMaxRelations ( relations , list ) ) ;
      }
    }
  }
  return max ;
}

public static int getMaxRelations ( HashMap < Integer , ArrayList < Integer > > relations , ArrayList < Integer > friends ) { int max = 1 ; for ( int data : friends ) { if ( relations . containsKey ( data ) ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int temp : relations . get ( data ) ) { if ( friends . contains ( temp ) ) { list . add ( temp ) ; } } if ( list . size ( ) != 0 ) { max = Math . max ( max , 1 + getMaxRelations ( relations , list ) ) ; } } } return max ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) name: (identifier)) (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) 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 (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (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 (type_identifier))) arguments: (argument_list)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))))))))) (return_statement (identifier))))