Class Solution
- java.lang.Object
-
- g1901_2000.s1960_maximum_product_of_the_length_of_two_palindromic_substrings.Solution
-
public class Solution extends Object
1960 - Maximum Product of the Length of Two Palindromic Substrings.Hard
You are given a 0-indexed string
sand 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,lsuch that0 <= i <= j < k <= l < s.lengthand both the substringss[i...j]ands[k...l]are palindromes and have odd lengths.s[i...j]denotes a substring from indexito indexjinclusive.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.
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.
Constraints:
2 <= s.length <= 105sconsists of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
-
-
Method Detail
-
maxProduct
public long maxProduct(String s)
-
-