Largest Palindrome Product - Problem
Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digit integers.
Since the result can be very large, return it modulo 1337.
For example, if n = 2, we need to find the largest palindrome that is the product of two 2-digit numbers (from 10 to 99). The largest palindrome would be 9009 = 91 × 99.
Note: For n = 1, the answer is 9 since 3 × 3 = 9 is the largest palindromic product of two 1-digit numbers.
Input & Output
Example 1 — Basic Case
$
Input:
n = 2
›
Output:
906
💡 Note:
We need the largest palindrome from products of 2-digit numbers (10-99). The largest is 9009 = 91 × 99. Return 9009 % 1337 = 906.
Example 2 — Single Digit
$
Input:
n = 1
›
Output:
9
💡 Note:
For 1-digit numbers (1-9), the largest palindromic product is 3 × 3 = 9. Since 9 < 1337, we return 9.
Example 3 — Larger Case
$
Input:
n = 3
›
Output:
123
💡 Note:
For 3-digit numbers (100-999), we find the largest palindromic product and return it modulo 1337. The actual palindrome is much larger than 1337.
Constraints
- 1 ≤ n ≤ 8
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given n=2, we work with 2-digit numbers (10 to 99)
2
Process
Find products that form palindromes: 91×99=9009
3
Output
Return largest palindrome modulo 1337: 906
Key Takeaway
🎯 Key Insight: Generate palindromes from largest to smallest instead of checking all products
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code