Well defined with bitmask. Beats 100%. O(N^2 * 2^N).
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nFind all subpalindromes
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind all subpalindromes.\nTraverse subpalindromes\n---- if pair.isDisjoint\n-------- currentProduct = length1 * length2\n-------- currentMax = (maxProduct, currentProduct)\nreturn maxProduct\n\n\n# Complexity\n- Time complexity: O(N^2 * 2^N).\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(2^N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nUpvotes appreciated. Happy coding.\n# Code\n```\nclass Solution {\n    func maxProduct(_ s: String) -> Int {\n        func areDisjoint(_ mask1: Int, _ mask2: Int) -> Bool { mask1 & mask2 == 0 }\n\n        func subPalindromes(_ characters: [Character]) -> [(Int, Int)] {\n            func isPalindrome(_ array: [Character]) -> Bool {\n                for i in 0..<(array.count / 2) where array[i] != array[array.count - 1 - i] { return false }\n                return true\n            }\n\n            var palindromicSubsequences = [(Int, Int)]()\n            let number = characters.count\n            (1..<(1 << number)).forEach { mask in\n                var subWord = [Character]()\n                for i in 0..<number where (mask & (1 << i)) != 0 { subWord.append(characters[i]) }\n                if isPalindrome(subWord) {\n                    palindromicSubsequences.append((mask, subWord.count)) \n                }\n            }\n            return palindromicSubsequences\n        }\n\n        let characters = Array(s)\n        var maxProduct = 0\n        guard !characters.isEmpty else { return maxProduct }\n        let palindromicSubsequences = subPalindromes(characters)\n        let count = palindromicSubsequences.count\n        (0..<count).forEach { i in\n            ((i + 1)..<count).forEach { j in\n                let (mask1, lenght1) = palindromicSubsequences[i]\n                let (mask2, lenght2) = palindromicSubsequences[j]\n                if areDisjoint(mask1, mask2) { maxProduct = max(maxProduct, lenght1 * lenght2) }\n            }\n        }\n        \n        return maxProduct\n    }\n}\n\n```
['Swift']