Skip to content

Practice Maximum Product of the Length of Two Palindromic Substrings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1960
LeetCode Problem

Maximum Product of the Length of Two Palindromic Substrings

Problem Statement

You are given a 0-indexed string s and are tasked with finding two non-intersecting palindromic substrings of odd length such that the product of their lengths is maximized. More formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.length and both the substrings s[i...j] and s[k...l] are palindromes and have odd lengths. s[i...j] denotes a substring from index i to index j inclusive. Return the maximum possible product of the lengths of the two non-intersecting palindromic substrings. A palindrome is a string that is the same forward and backward. A substring is a contiguous sequence of characters in a string.

Source: Maximum Product of the Length of Two Palindromic Substrings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "ababbb"
Output
9

# Example 2

Input
s = "zaaaxbbby"
Output
9

Constraints

2 <= s.length <= 10^5
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Maximum Product of the Length of Two Palindromic Substrings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.