Letter Case Permutation

Given a string s, you may change any letter in it to lowercase or uppercase independently. Return a list of every string you can create this way, in any order.

30:00

Letter Case Permutation
medium
Free written solution
Topics
Companies

Given a string s, you may change any letter in it to lowercase or uppercase independently. Return a list of every string you can create this way, in any order.

Example 1:
Input: {"s":"a1b2"}
Output: ["a1b2","A1b2","a1B2","A1B2"]
Constraints:
  • 1≤s.length≤121 \leq \text{s.length} \leq 12

  • s consists of lowercase English letters, uppercase English letters, and digits.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"a1b2"}

"a1b2" has 2 letters. Give each one a switch: bit b of a mask says whether letter b is uppercase. 2 switches give 2^2 = 4 strings.

Each letter is a switch: lower (0) or UPPER (1)

a
bit 0
1
fixed
b
bit 1
2
fixed

Digits never change. Counting the mask from 0 to 3 visits every on/off pattern of the 2 switches exactly once.

masks done

0 / 4

0
1
2
3

result

[ ]

Variables
VariableValue
k2
masks4
DepthFunction Call
Stack empty
0/17