Expand Independent Character Choices

Quick Overview

Expand Independent Character Choices. The valid string s describes one or more words. A plain lowercase letter fixes one position; a nonnested brace group such as {x,y} offers distinct single-letter choices for that position.

Expand Independent Character Choices

Company: Anduril

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The valid string s describes one or more words. A plain lowercase letter fixes one position; a nonnested brace group such as `{x,y}` offers distinct single-letter choices for that position. Concatenate one choice from each position and return all resulting words in lexicographic order. ```cpp class Solution { public: vector<string> expand(string s); }; ``` ### Examples **Example 1:** ```text Input: s = "q{c,a}{x,z}" Output: ["qax","qaz","qcx","qcz"] Explanation: Choose a or c, then x or z, after the fixed q. ``` **Example 2:** ```text Input: s = "{z,b}a" Output: ["ba","za"] Explanation: Sorting the first-position options determines the word order. ``` ### Constraints - The expression contains 1 to 50 characters. - Only lowercase letters, braces and commas occur, and the input is valid. - Braces never nest. Letters within each brace group are distinct. ### Contract considerations Return the complete sorted list. The ordered result is deterministic. ```hint Read the boundary condition Does a brace group contribute one output character, or should its punctuation appear in the returned word? ``` ### Boundary reminders Return the complete sorted list. The ordered result is deterministic.

Overview: Expand Independent Character Choices. The valid string s describes one or more words. A plain lowercase letter fixes one position; a nonnested brace group such as {x,y} offers distinct single-letter choices for that position.

Anduril logo
Anduril
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The valid string s describes one or more words. A plain lowercase letter fixes one position; a nonnested brace group such as {x,y} offers distinct single-letter choices for that position. Concatenate one choice from each position and return all resulting words in lexicographic order.

class Solution {
public:
    vector<string> expand(string s);
};

Examples

Example 1:

Input: s = "q{c,a}{x,z}"
Output: ["qax","qaz","qcx","qcz"]
Explanation: Choose a or c, then x or z, after the fixed q.

Example 2:

Input: s = "{z,b}a"
Output: ["ba","za"]
Explanation: Sorting the first-position options determines the word order.

Constraints

  • The expression contains 1 to 50 characters.
  • Only lowercase letters, braces and commas occur, and the input is valid.
  • Braces never nest. Letters within each brace group are distinct.

Contract considerations

Return the complete sorted list. The ordered result is deterministic.

Boundary reminders

Return the complete sorted list. The ordered result is deterministic.