static int minimumNoOfPalindromes ( int N ) {
  String a = String . valueOf ( N ) ;
  String b = String . valueOf ( N ) ;
  b = reverse ( b ) ;
  if ( a . equals ( b ) ) {
    return 1 ;
  }
  Vector < Integer > palindromes = generatePalindromes ( N ) ;
  Collections . sort ( palindromes ) ;
  int l = 0 , r = palindromes . size ( ) - 1 ;
  while ( l < r ) {
    if ( palindromes . get ( l ) + palindromes . get ( r ) == N ) {
      return 2 ;
    }
    else if ( palindromes . get ( l ) + palindromes . get ( r ) < N ) {
      ++ l ;
    }
    else {
      -- r ;
    }
  }
  return 3 ;
}

static int minimumNoOfPalindromes ( int N ) { String a = String . valueOf ( N ) ; String b = String . valueOf ( N ) ; b = reverse ( b ) ; if ( a . equals ( b ) ) { return 1 ; } Vector < Integer > palindromes = generatePalindromes ( N ) ; Collections . sort ( palindromes ) ; int l = 0 , r = palindromes . size ( ) - 1 ; while ( l < r ) { if ( palindromes . get ( l ) + palindromes . get ( r ) == N ) { return 2 ; } else if ( palindromes . get ( l ) + palindromes . get ( r ) < N ) { ++ l ; } else { -- r ; } } return 3 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (return_statement (decimal_integer_literal)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (identifier))) consequence: (block (return_statement (decimal_integer_literal))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (update_expression (identifier)))))))) (return_statement (decimal_integer_literal))))