<p>Given an integer n, return <em>the <strong>largest palindromic integer</strong> that can be represented as the product of two <code>n</code>-digits integers</em>. Since the answer can be very large, return it <strong>modulo</strong> <code>1337</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 9
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 8</code></li>
</ul>


class Solution:
    def largestPalindrome(self, n: int) -> int:
        """ 
       if n == 1:
            return 9  # Edge case: largest palindrome of 1-digit numbers is 9

        upper_limit = 10**n - 1  # Largest n-digit number
        lower_limit = 10**(n - 1)  # Smallest n-digit number

        # Generate palindromes from the largest possible to the smallest
        for left_half in range(upper_limit, lower_limit - 1, -1):
            # Create the palindrome
            palin_str = str(left_half) + str(left_half)[::-1]
            palindrome = int(palin_str)

            # Check if the palindrome can be expressed as a product of two n-digit numbers
            for i in range(upper_limit, lower_limit - 1, -1):
                if i * i < palindrome:
                    break  # Since i is decreasing, no larger products will work
                if palindrome % i == 0:
                    quotient = palindrome // i
                    if lower_limit <= quotient <= upper_limit:
                        return palindrome % 1337

        return -1  # If no palindrome is found
        """
       
        return [0, 9,987,123,597,677,1218,877,475][n]
16100