bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 479. Largest Palindrome Product

479. Largest Palindrome Product

Leetcode Solutions

Constructing Palindromes and Checking Divisibility

  1. If n is 1, return 9 as the largest palindrome.
  2. Calculate the highest (hi) and lowest (lo) n-digit numbers.
  3. Iterate from hi to lo in a descending order: a. Convert the current number i to a string s. b. Create a palindromic string by appending the reverse of s to s itself. c. Convert the palindromic string back to an integer ll.
  4. For each palindrome ll, iterate from hi to the square root of ll: a. Check if ll is divisible by the current number j. b. If it is, and the quotient is also an n-digit number, return ll modulo 1337.
  5. If no palindrome is found, return 0.
UML Thumbnail

From Product to Palindrome

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...