1
# Runtime: 1302 ms (Top 13.95%) | Memory: 35.7 MB (Top 6.05%)3
we can approach this problem using manacher's algorithm with backtracking and recursion8
def partition(self, s: str) -> List[List[str]]:17
for k in range(len(s)):20
# check for odd length palindromes21
while i >= 0 and j < len(s) and s[i] == s[j]:24
for partition in lps(s[:i]):25
res.append(partition + [s[i : j + 1]])27
for part in lps(s[j + 1 :]):28
temp = partition + part29
if tuple(temp) not in result_set:30
result_set.add(tuple(temp))31
final_res.append(temp)35
# check for even length palindromes37
while i >= 0 and j < len(s) and s[i] == s[j]:40
for partition in lps(s[:i]):41
res.append(partition + [s[i : j + 1]])43
for part in lps(s[j + 1 :]):44
temp = partition + part45
if tuple(temp) not in result_set:46
result_set.add(tuple(temp))47
final_res.append(temp)