You're tasked with finding the largest palindrome that can be formed by multiplying two n-digit numbers. A palindrome reads the same forwards and backwards (like 12321 or 9009).
Given an integer n, return the largest palindromic integer that is the product of two n-digit integers. For example, if n = 2, you need to find the largest palindrome formed by multiplying two 2-digit numbers (10-99).
Since the result can be extremely large, return it modulo 1337.
Key Challenge: The brute force approach of checking all possible products becomes computationally expensive for larger values of n. We need to work backwards from the largest possible palindrome!
Input & Output
Visualization
Time & Space Complexity
We generate palindromes by their first half, and for each palindrome we do factorization check
Only using constant extra space for calculations and variables
Constraints
- 1 โค n โค 8
- The result must be returned modulo 1337
- Both factors must be exactly n-digit numbers