Tap here to switch tabs
Problem
Submissions

Problem: Brace Expansion II

med
30 min
Try to solve the Brace Expansion II problem.

Statement

Under the specified grammar, an expression evaluates to a set of strings:

  • A single lowercase letter evaluates to a set containing just that character.

  • The union of two or more expressions enclosed in curly braces {e_1, e_2, ...} evaluates to the union of the sets generated by e1,e2,…e_1, e_2, \dots.

  • The concatenation of two expressions e1e2e_1 e_2 evaluates to the set formed by concatenating every word from e1e_1 with every word from e2e_2.

Given a string expression representing a valid grammar expression, return the sorted list of all unique words generated by the expression.

Constraints:

  • 1≤1 \leq expression.length ≤60\leq 60

  • expression[i] consists of '{', '}', ',', or lowercase English letters.

  • The given expression represents a set of words based on the grammar given in the description.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Brace Expansion II

med
30 min
Try to solve the Brace Expansion II problem.

Statement

Under the specified grammar, an expression evaluates to a set of strings:

  • A single lowercase letter evaluates to a set containing just that character.

  • The union of two or more expressions enclosed in curly braces {e_1, e_2, ...} evaluates to the union of the sets generated by e1,e2,…e_1, e_2, \dots.

  • The concatenation of two expressions e1e2e_1 e_2 evaluates to the set formed by concatenating every word from e1e_1 with every word from e2e_2.

Given a string expression representing a valid grammar expression, return the sorted list of all unique words generated by the expression.

Constraints:

  • 1≤1 \leq expression.length ≤60\leq 60

  • expression[i] consists of '{', '}', ',', or lowercase English letters.

  • The given expression represents a set of words based on the grammar given in the description.