Largest Palindrome Product - Wrong test-case answer


  • 0
    S

    I think one of the test case fore this problem is damn wrong. If you put 1 as an input my code returning product as 66 which is correct palindrome where as the question expecting answer to be. My code is as follows :

        public static int largestPalindrome(int n) {
            long product =  0;
            long product_start = ((long) Math.pow(10, n-1))*((long) Math.pow(10, n-1)+1);
            long product_end = ((long) Math.pow(10, n)-2) * ((long) Math.pow(10, n)-1);
            for (long i = product_start; i<=product_end; i++) {
                //call palindrome
                if(isPal(String.valueOf(i))) {
                    if (product<i) {
                        product = i;
                    }
                }
            }
            return (int) product%1337;
        }
    
        public static boolean isPal(String str) {
            if(str.length()==0 || str.length() ==1) {
                return true;
            }
            else {
                if(str.charAt(0) == str.charAt(str.length()-1)) {
                    String subString = str.substring(1, str.length()-1);
                    return isPal(str.substring(1, str.length() - 1));
                } else {
                    return false;
                }
            }
        }
    

  • 0
    N

    66 = 11 * 6 and 11 has two digits, so it can't be correct answer.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.