Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Generate letter case permutations

Return all permutations of a string where alphabetic characters can be either lowercase or uppercase.

Python practice15 minRecursion & BacktrackingIntermediateLast updated March 27, 2026

Problem statement

Given a string s consisting of letters and digits, generate all possible strings by changing the case of each letter independently. Digits should remain the same. Return the list of permutations in a deterministic order: process characters left-to-right, and for letters try lowercase first then uppercase.

Task

Use recursion/backtracking to toggle case on letters and keep digits unchanged to produce all permutations.

Examples

Example - s = 'a1b'

Input

a1b

Output

['a1b', 'a1B', 'A1b', 'A1B']

For 'a' try 'a' then 'A'; for 'b' try 'b' then 'B'. Digits unchanged.

Input format

A single string s (letters and digits).

Output format

A list of strings representing all case permutations (deterministic order).

Constraints

0 <= len(s) <= 12. Maintain input character order; for each letter try lowercase before uppercase.

Samples

Sample 1

Input

3z4

Output

['3z4', '3Z4']

Only the letter 'z' has case variations.