Skip to content

Maximum Length of a Concatenated String with Unique Characters

MediumBacktracking
Decode it first. Clues, constraints, pattern and plan before any code.

You are given a list of strings arr. Choose any subsequence of them (keep or drop each string, keeping their order) and glue the chosen ones together. The glued string must have all unique characters. Return the maximum possible length of such a string. Choosing nothing gives length 0.

["un", "iq", "ue"]          →  4   ("uniq" or "ique")
["cha", "r", "act", "ers"]  →  6   ("chaers" or "acters")
["aa", "bb"]                 →  0   (each string repeats a letter)

Constraints

  • 1 <= arr.length <= 16
  • 1 <= arr[i].length <= 26
  • arr[i] contains only lowercase English letters.