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
Largest Palindrome Product: n=2 ExampleInput: n = 22-digit range:10 to 99Products99×99 = 980191×99 = 9009Palindrome Check9801 ≠ 1089 ❌9009 = 9009 ✅ResultLargest: 90099009 % 1337 = 906Key insight: 9009 reads the same forwards (9-0-0-9) and backwardsIt's the largest such palindrome from 2-digit number productsOutput: 906
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
Asked in
Google 12 Facebook 8 Microsoft 6
12.5K Views
Medium Frequency
~35 min Avg. Time
234 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen