Letter Case Permutation — Backtracking

Produce every spelling of a short scanned device code where each letter may appear in either case while digits stay fixed.

Backtracking · Easy

The problem

A device serial code is made of letters and digits. Scanners may read each letter as either upper or lower case, but digits never change. Given the code s, return every distinct string you can get by changing the case of any of its letters. Return them in any order.

The story

A warehouse scanner reads a device code of 1 to 8 letters and digits, but it cannot tell whether each letter is upper or lower case. Digits are always read correctly. List every distinct code the scanner might have meant: each letter can be either case, and each digit stays as it is.

What to return

Constraints

Example

Input
s = "a1b"
Output
["a1b", "A1b", "a1B", "A1B"]

Solve it

More in Backtracking

All algorithm problems