Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2002 - Maximum Product of the Length of Two Palindromic Subsequences.

    Medium

    Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.

    Return the maximum possible product of the lengths of the two palindromic subsequences.

    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is palindromic if it reads the same forward and backward.

    Example 1:

    Input: s = "leetcodecom"

    Output: 9

    Explanation: An optimal solution is to choose "ete" for the 1<sup>st</sup> subsequence and "cdc" for the 2<sup>nd</sup> subsequence.

    The product of their lengths is: 3 \* 3 = 9.

    Example 2:

    Input: s = "bb"

    Output: 1

    Explanation: An optimal solution is to choose "b" (the first character) for the 1<sup>st</sup> subsequence and "b" (the second character) for the 2<sup>nd</sup> subsequence.

    The product of their lengths is: 1 \* 1 = 1.

    Example 3:

    Input: s = "accbcaxxcxx"

    Output: 25

    Explanation: An optimal solution is to choose "accca" for the 1<sup>st</sup> subsequence and "xxcxx" for the 2<sup>nd</sup> subsequence.

    The product of their lengths is: 5 \* 5 = 25.

    Constraints:

    • 2 &lt;= s.length &lt;= 12

    • s consists of lowercase English letters only.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maxProduct(String s)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait