public static int minOperations ( int [ ] a , int n , int K ) {
  HashMap < Integer , Boolean > map = new HashMap < > ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    try {
      if ( map . get ( a [ i ] ) ) return 1 ;
    }
    catch ( Exception e ) {
    }
    try {
      map . put ( a [ i ] , true ) ;
    }
    catch ( Exception e ) {
    }
  }
  int [ ] b = new int [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) b [ i ] = a [ i ] & K ;
  map . clear ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( a [ i ] != b [ i ] ) {
      try {
        map . put ( b [ i ] , true ) ;
      }
      catch ( Exception e ) {
      }
    }
  }
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    try {
      if ( map . get ( a [ i ] ) ) return 1 ;
    }
    catch ( Exception e ) {
    }
  }
  map . clear ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    try {
      if ( map . get ( b [ i ] ) ) return 2 ;
    }
    catch ( Exception e ) {
    }
    try {
      map . put ( b [ i ] , true ) ;
    }
    catch ( Exception e ) {
    }
  }
  return - 1 ;
}

public static int minOperations ( int [ ] a , int n , int K ) { HashMap < Integer , Boolean > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { try { if ( map . get ( a [ i ] ) ) return 1 ; } catch ( Exception e ) { } try { map . put ( a [ i ] , true ) ; } catch ( Exception e ) { } } int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = a [ i ] & K ; map . clear ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { try { map . put ( b [ i ] , true ) ; } catch ( Exception e ) { } } } for ( int i = 0 ; i < n ; i ++ ) { try { if ( map . get ( a [ i ] ) ) return 1 ; } catch ( Exception e ) { } } map . clear ( ) ; for ( int i = 0 ; i < n ; i ++ ) { try { if ( map . get ( b [ i ] ) ) return 2 ; } catch ( Exception e ) { } try { map . put ( b [ i ] , true ) ; } catch ( Exception e ) { } } return - 1 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (try_statement body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (return_statement (decimal_integer_literal)))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))) (try_statement body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (true))))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (try_statement body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (true))))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (try_statement body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (return_statement (decimal_integer_literal)))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (try_statement body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (return_statement (decimal_integer_literal)))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))) (try_statement body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (true))))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block))))) (return_statement (unary_expression operand: (decimal_integer_literal)))))