#1960
Maximum Product of the Length of Two Palindromic Substrings
international master · 1965 · lc hard +32 · verified · 31% accepted · 255 likes · top 8%
Description
Given a 0-indexed string s, select four indices i, j, k, l satisfying 0 <= i <= j < k <= l < s.length so that both s[i...j] and s[k...l] are palindromic substrings with odd lengths. The two substrings must not overlap. Return the maximum product of their lengths.
Recall that a palindrome reads the same forwards and backwards, and a substring is any contiguous segment of characters within the string.
Example 1:
Input: s = "ababbb"
Output: 9
Explanation: Substrings "aba" and "bbb" are palindromes with odd length. product = 3 * 3 = 9.
Example 2:
Input: s = "zaaaxbbby"
Output: 9
Explanation: Substrings "aaa" and "bbb" are palindromes with odd length. product = 3 * 3 = 9.
Code
1
2
3