Palindrome partitions

Write codeMedium25 min

Your task

Given a string s, return all ways to partition s such that every substring of the partition is a palindrome. Each partition is a list of substrings (in order); return the list of partitions sorted lexicographically (comparing the lists of pieces). s has at most 16 lowercase letters.

Examples

partition_palindromes(s: str) -> list[list[str]]
Example 1
Inputpartition_palindromes("aab")
Output[["a", "a", "b"], ["aa", "b"]]