Generate every string formed by toggling the letter cases in the input string while leaving digits unchanged.
Letter Case Permutation
You are given a string s consisting of letters and digits.
Generate all possible strings that can be formed by independently changing each alphabetic character to either lowercase or uppercase. Digits must remain unchanged.
Return all distinct permutations in any order.
Notes
- Each letter can be chosen in one of two cases.
- Non-letter characters are not modified.
- The same output string should not appear more than once.
Input Format
- A single string
s. scontains only English letters and digits.
Output Format
- Return a list of all valid case permutations of
sin any order.
Constraints
1 <= s.length <= 12scontains only letters and digits.- The number of alphabetic characters may be up to the length of the string.
Example 1
Input
s = "a1b2"
Output
["a1b2","a1B2","A1b2","A1B2"]
Explanation
The letters a and b can each be lowercase or uppercase, while digits stay unchanged.
Example 2
Input
s = "3z4"
Output
["3z4","3Z4"]
Explanation
Only z changes case; the digits 3 and 4 remain the same.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.