<p>You are given a <strong>0-indexed</strong> string <code>s</code> and are tasked with finding two <strong>non-intersecting palindromic </strong>substrings of <strong>odd</strong> length such that the product of their lengths is maximized.</p>

<p>More formally, you want to choose four integers <code>i</code>, <code>j</code>, <code>k</code>, <code>l</code> such that <code>0 &lt;= i &lt;= j &lt; k &lt;= l &lt; s.length</code> and both the substrings <code>s[i...j]</code> and <code>s[k...l]</code> are palindromes and have odd lengths. <code>s[i...j]</code> denotes a substring from index <code>i</code> to index <code>j</code> <strong>inclusive</strong>.</p>

<p>Return <em>the <strong>maximum</strong> possible product of the lengths of the two non-intersecting palindromic substrings.</em></p>

<p>A <strong>palindrome</strong> is a string that is the same forward and backward. A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>

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

<pre>
<strong>Input:</strong> s = &quot;ababbb&quot;
<strong>Output:</strong> 9
<strong>Explanation:</strong> Substrings &quot;aba&quot; and &quot;bbb&quot; are palindromes with odd length. product = 3 * 3 = 9.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;zaaaxbbby&quot;
<strong>Output:</strong> 9
<strong>Explanation:</strong> Substrings &quot;aaa&quot; and &quot;bbb&quot; are palindromes with odd length. product = 3 * 3 = 9.
</pre>

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

<ul>
	<li><code>2 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution:
    def __init__(self):
        self.base = 29
        self.mod = 2**31 - 1  # equivalent to Integer.MAX_VALUE in Java

    def is_palindromic(self, left, right, lh, rh, pow):
        """Check if a substring is palindromic using hash values."""
        return self.lh(left, right, lh, pow) == self.rh(left, right, rh, pow)

    def lh(self, left, right, hash, pow):
        """Calculate the hash value of a substring from the left."""
        ans = (hash[right] - hash[left] * pow[right - left]) % self.mod
        if ans < 0:
            ans += self.mod
        return ans

    def rh(self, left, right, hash, pow):
        """Calculate the hash value of a substring from the right."""
        ans = (hash[left] - hash[right] * pow[right - left]) % self.mod
        if ans < 0:
            ans += self.mod
        return ans

    def maxProduct(self, s):
        """Find the maximum product of two non-overlapping palindromic substrings."""
        n = len(s)

        # Precompute powers of the base
        pow = [1] * (n + 1)
        for i in range(1, n + 1):
            pow[i] = pow[i - 1] * self.base % self.mod

        # Precompute hash values from the left and right
        lh = [0] * (n + 1)
        for i in range(1, n + 1):
            lh[i] = (lh[i - 1] * self.base + ord(s[i - 1]) - ord('a')) % self.mod

        rh = [0] * (n + 1)
        for i in range(n - 1, -1, -1):
            rh[i] = (rh[i + 1] * self.base + ord(s[i]) - ord('a')) % self.mod

        # Find the maximum length of palindromic substrings from the left and right
        left = [0] * n
        max_len = 1
        for i in range(n):
            if max_len < i and self.is_palindromic(i - max_len - 1, i + 1, lh, rh, pow):
                max_len += 2
            left[i] = max_len

        right = [0] * n
        max_len = 1
        for i in range(n - 1, -1, -1):
            if i + max_len + 2 <= n and self.is_palindromic(i, i + max_len + 2, lh, rh, pow):
                max_len += 2
            right[i] = max_len

        # Find the maximum product of two non-overlapping palindromic substrings
        ans = 1
        for i in range(1, n):
            ans = max(ans, left[i - 1] * right[i])
        return ans
1266