package leetcode;

import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/
 */
public class Problem1239 {
    public int maxLength(List<String> arr) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1239 prob = new Problem1239();
        System.out.println(prob.maxLength(Arrays.asList("un","iq","ue"))); // 4
        System.out.println(prob.maxLength(Arrays.asList("cha","r","act","ers"))); // 6
        System.out.println(prob.maxLength(Arrays.asList("abcdefghijklmnopqrstuvwxyz"))); // 26
    }
}

@@ -54,20 +54,68 @@
 va.util.
-List
+HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -298,32 +298,1204 @@
     
-// TODO%0A        return 0
+int answer = 0;%0A        Map%3CString, Integer%3E memo = new HashMap%3C%3E();%0A        for (int i = 0; i %3C arr.size(); i++) %7B%0A            answer = Math.max(answer, maxLength(arr, i, %22%22, memo));%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static int maxLength(List%3CString%3E arr, int index, String accu, Map%3CString, Integer%3E memo) %7B%0A        if (arr.size() == index) %7B%0A            return accu.length();%0A        %7D%0A        String key = index + %22,%22 + accu;%0A        if (memo.containsKey(key)) %7B%0A            return memo.get(key);%0A        %7D%0A        int max = 0;%0A        for (int i = index; i %3C arr.size(); i++) %7B%0A            String s = arr.get(i);%0A            if (isUnique(accu + s)) %7B%0A                max = Math.max(max, maxLength(arr, i + 1, accu + s, memo));%0A            %7D else %7B%0A                max = Math.max(max, maxLength(arr, i + 1, accu, memo));%0A            %7D%0A        %7D%0A        memo.put(key, max);%0A        return max;%0A    %7D%0A%0A    private static boolean isUnique(String s) %7B%0A        boolean%5B%5D count = new boolean%5B26%5D;%0A        for (char c : s.toCharArray()) %7B%0A            if (count%5Bc - 'a'%5D) %7B%0A                return false;%0A            %7D%0A            count%5Bc - 'a'%5D = true;%0A        %7D%0A        return true
 ;%0A  
@@ -1655,13 +1655,15 @@
 un%22,
+ 
 %22iq%22,
+ 
 %22ue%22
@@ -1738,18 +1738,21 @@
 ha%22,
+ 
 %22r%22,
+ 
 %22act%22,
+ 
 %22ers

Update problem 1239