Letter Case Permutation - Problem

Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.

Return a list of all possible strings we could create. Return the output in any order.

Note: Only alphabetic characters can be transformed - digits and special characters remain unchanged.

Input & Output

Example 1 — Basic Case
$ Input: s = "a1b2"
Output: ["a1b2","a1B2","A1b2","A1B2"]
💡 Note: Two letters 'a' and 'b' can each be upper or lower case. 2×2 = 4 combinations total.
Example 2 — Single Character
$ Input: s = "3z4"
Output: ["3z4","3Z4"]
💡 Note: Only one letter 'z', so 2 possibilities: lowercase 'z' or uppercase 'Z'.
Example 3 — No Letters
$ Input: s = "12345"
Output: ["12345"]
💡 Note: No letters to transform, so only one result: the original string.

Constraints

  • 1 ≤ s.length ≤ 12
  • s consists of lowercase English letters, uppercase English letters, and digits

Visualization

Tap to expand
Letter Case Permutation OverviewInput: "a1b2"Letters can change:a/A1b/B2Digits stay same2 letters × 2 cases each = 4 combinations"a1b2""a1B2""A1b2""A1B2"Output: All possible case permutations
Understanding the Visualization
1
Input
String "a1b2" with mixed letters and digits
2
Transform
Each letter can be upper or lower case
3
Output
All possible case combinations
Key Takeaway
🎯 Key Insight: Each letter doubles the total combinations, creating 2^n permutations
Asked in
Google 15 Facebook 12 Amazon 8
185.0K Views
Medium Frequency
~15 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen