static int maximumXor ( int arr [ ] , int n ) {
  Stack < Integer > sForward = new Stack < Integer > ( ) , sBackward = new Stack < Integer > ( ) ;
  int ans = - 1 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    while ( ! sForward . isEmpty ( ) && arr [ i ] < arr [ sForward . peek ( ) ] ) {
      ans = Math . max ( ans , arr [ i ] ^ arr [ sForward . peek ( ) ] ) ;
      sForward . pop ( ) ;
    }
    sForward . add ( i ) ;
    while ( ! sBackward . isEmpty ( ) && arr [ n - i - 1 ] < arr [ sBackward . peek ( ) ] ) {
      ans = Math . max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward . peek ( ) ] ) ;
      sBackward . pop ( ) ;
    }
    sBackward . add ( n - i - 1 ) ;
  }
  return ans ;
}

static int maximumXor ( int arr [ ] , int n ) { Stack < Integer > sForward = new Stack < Integer > ( ) , sBackward = new Stack < Integer > ( ) ; int ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { while ( ! sForward . isEmpty ( ) && arr [ i ] < arr [ sForward . peek ( ) ] ) { ans = Math . max ( ans , arr [ i ] ^ arr [ sForward . peek ( ) ] ) ; sForward . pop ( ) ; } sForward . add ( i ) ; while ( ! sBackward . isEmpty ( ) && arr [ n - i - 1 ] < arr [ sBackward . peek ( ) ] ) { ans = Math . max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward . peek ( ) ] ) ; sBackward . pop ( ) ; } sBackward . add ( n - i - 1 ) ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) 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 (type_identifier))) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (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 (while_statement condition: (parenthesized_expression (binary_expression left: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (while_statement condition: (parenthesized_expression (binary_expression left: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))))))) (return_statement (identifier))))