<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 maxProduct(self, s: str) -> int:
    kBase = 26
    kHash = 1_000_000_007
    n = len(s)
    pows = [1]  # pows[i] := kBase^i % kHash
    # hashL[i] = the hash of the first i letters of s, where hashL[i] =
    # (26^(i - 1) * s[0] + 26^(i - 2) * s[1] + ... + s[i - 1]) % kHash
    hashL = [0]
    # hashR[i] = the hash of the last i letters of s, where hashR[i] =
    # (26^(i - 1) * s[-1] + 26^(i - 2) * s[-2] + ... + s[-i]) % kHash
    hashR = [0]
    # maxLeft[i] := the maximum odd length of palindromes in s[0..i]
    maxLeft = [0] * n
    # maxRight[i] := the maximum odd length of palindromes in s[i..n - 1]
    maxRight = [0] * n

    def val(c: str) -> int:
      return string.ascii_lowercase.index(c)

    for _ in range(n):
      pows.append(pows[-1] * kBase % kHash)

    for c in s:
      hashL.append((hashL[-1] * kBase + val(c)) % kHash)

    for c in reversed(s):
      hashR.append((hashR[-1] * kBase + val(c)) % kHash)

    hashR.reverse()

    def leftHash(l: int, r: int) -> int:
      """Returns the left hash of s[l..r)."""
      h = (hashL[r] - hashL[l] * pows[r - l]) % kHash
      return h + kHash if h < 0 else h

    def rightHash(l: int, r: int) -> int:
      """Returns the right hash of s[l..r)."""
      h = (hashR[l] - hashR[r] * pows[r - l]) % kHash
      return h + kHash if h < 0 else h

    def isPalindrome(l: int, r: int) -> bool:
      """Returns True if s[l..r) is a palindrome."""
      return leftHash(l, r) == rightHash(l, r)

    maxLength = 1
    for r in range(n):
      l = (r - maxLength - 2) + 1
      if l >= 0 and isPalindrome(l, r + 1):
        maxLength += 2
      maxLeft[r] = maxLength

    maxLength = 1
    for l in reversed(range(n)):
      r = (l + maxLength + 2) - 1
      if r < n and isPalindrome(l, r + 1):
        maxLength += 2
      maxRight[l] = maxLength

    return max(maxLeft[i - 1] * maxRight[i] for i in range(1, n))

1069