Skip to content

Commit 870ee8a

Browse files
committed
2002. Maximum Product of the Length of Two Palindromic Subsequences: RETRY
1 parent 95c6dd8 commit 870ee8a

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,3 +1509,4 @@ mod s1997_first_day_where_you_have_been_in_all_the_rooms;
15091509
mod s1998_gcd_sort_of_an_array;
15101510
mod s2000_reverse_prefix_of_word;
15111511
mod s2001_number_of_pairs_of_interchangeable_rectangles;
1512+
mod s2002_maximum_product_of_the_length_of_two_palindromic_subsequences;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* [2002] Maximum Product of the Length of Two Palindromic Subsequences
3+
*
4+
* 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.
5+
* Return the maximum possible product of the lengths of the two palindromic subsequences.
6+
* 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.
7+
*
8+
* Example 1:
9+
* <img alt="example-1" src="https://assets.leetcode.com/uploads/2021/08/24/two-palindromic-subsequences.png" style="width: 550px; height: 124px;" />
10+
* Input: s = "leetcodecom"
11+
* Output: 9
12+
* Explanation: An optimal solution is to choose "ete" for the 1^st subsequence and "cdc" for the 2^nd subsequence.
13+
* The product of their lengths is: 3 * 3 = 9.
14+
*
15+
* Example 2:
16+
*
17+
* Input: s = "bb"
18+
* Output: 1
19+
* Explanation: An optimal solution is to choose "b" (the first character) for the 1^st subsequence and "b" (the second character) for the 2^nd subsequence.
20+
* The product of their lengths is: 1 * 1 = 1.
21+
*
22+
* Example 3:
23+
*
24+
* Input: s = "accbcaxxcxx"
25+
* Output: 25
26+
* Explanation: An optimal solution is to choose "accca" for the 1^st subsequence and "xxcxx" for the 2^nd subsequence.
27+
* The product of their lengths is: 5 * 5 = 25.
28+
*
29+
*
30+
* Constraints:
31+
*
32+
* 2 <= s.length <= 12
33+
* s consists of lowercase English letters only.
34+
*
35+
*/
36+
pub struct Solution {}
37+
38+
// problem: https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/
39+
// discuss: https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
40+
41+
// submission codes start here
42+
43+
impl Solution {
44+
pub fn max_product(s: String) -> i32 {
45+
0
46+
}
47+
}
48+
49+
// submission codes end
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
55+
#[test]
56+
#[ignore]
57+
fn test_2002_example_1() {
58+
let s = "leetcodecom".to_string();
59+
60+
let result = 9;
61+
62+
assert_eq!(Solution::max_product(s), result);
63+
}
64+
65+
#[test]
66+
#[ignore]
67+
fn test_2002_example_2() {
68+
let s = "bb".to_string();
69+
70+
let result = 1;
71+
72+
assert_eq!(Solution::max_product(s), result);
73+
}
74+
75+
#[test]
76+
#[ignore]
77+
fn test_2002_example_3() {
78+
let s = "accbcaxxcxx".to_string();
79+
80+
let result = 25;
81+
82+
assert_eq!(Solution::max_product(s), result);
83+
}
84+
}

0 commit comments

Comments
 (0)