Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.44 KB

_1239. Maximum Length of a Concatenated String with Unique Characters.md

File metadata and controls

53 lines (38 loc) · 1.44 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 29, 2024

Last updated : June 29, 2024


Related Topics : Array, String, Backtracking, Bit Manipulation

Acceptance Rate : 54.14 %


Solutions

Python

class Solution:
    def maxLength(self, arr: List[str]) -> int:
        arrTuples = []

        for s in arr :
            stringSet = set(s)
            if len(s) == len(stringSet) :
                arrTuples.append(stringSet)


        self.maxx = 0
        def helper(current: set(), toTry: List[Set[str]]) -> None :
            self.maxx = max(self.maxx, len(current))
            if not toTry :
                return
            
            nextToTry = toTry.pop()
            helper(current, toTry)
            temp = nextToTry | current
            if len(current) + len(nextToTry) == len(temp) :
                helper(temp, toTry)
            toTry.append(nextToTry)

        helper(set(), arrTuples)
        return self.maxx