Skip to main content
Back to problems
Leetcode
Medium
Strings
Backtracking
Recursion
Letter Case Permutation

Generate every string formed by toggling the letter cases in the input string while leaving digits unchanged.

Acceptance 0%
Problem Statement

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.
  • s contains only English letters and digits.

Output Format

  • Return a list of all valid case permutations of s in any order.

Constraints

  • 1 <= s.length <= 12
  • s contains only letters and digits.
  • The number of alphabetic characters may be up to the length of the string.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.