Sorting the list of palindromes
palindromes . sort ( ) ; var l = 0 , r = palindromes . length - 1 ; while ( l < r ) { if ( palindromes [ l ] + palindromes [ r ] == N ) { return 2 ; } else if ( palindromes [ l ] + palindromes [ r ] < N ) { ++ l ; } else { -- r ; } }