Skip to content
Decoder

Maximum Length of a Concatenated String with Unique Characters

Medium

Problem

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.

Example 1

Input
["un", "iq", "ue"]
Output
4
Why
"uniq" or "ique"

Example 2

Input
["cha", "r", "act", "ers"]
Output
6
Why
"chaers" or "acters"

Example 3

Input
["aa", "bb"]
Output
0
Why
each string repeats a letter

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.