Skip to content

Commit ec6dbaf

Browse files
Create max_product_of_length_of_two_palindromic_sequences.py
1 parent fc473a7 commit ec6dbaf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def maxProduct(self, s: str) -> int:
3+
subs = []
4+
n = len(s)
5+
def dfs(curr, ind, inds):
6+
if ind == n:
7+
if curr == curr[::-1]:
8+
subs.append((curr, inds))
9+
return
10+
dfs(curr+s[ind], ind+1, inds|{ind})
11+
dfs(curr, ind+1, inds)
12+
13+
dfs('', 0, set())
14+
15+
res = 0
16+
n = len(subs)
17+
for i in range(n):
18+
s1, i1 = subs[i]
19+
for j in range(i+1, n):
20+
s2, i2 = subs[j]
21+
if len(i1 & i2) == 0:
22+
res = max(res, len(s1)*len(s2))
23+
return res

0 commit comments

Comments
 (0)