Skip to content
BytePatterns

Flip Letter Case Variants

EasyBacktracking#backtracking#include-exclude~15m

Problem

A string mixes letters and digits. Every letter may be written in lowercase or in uppercase, while digits never change. Return every string you can produce this way. List them so that, for each letter from left to right, the lowercase choice comes before the uppercase one.

Examples

Input:  s = "a1b"
Output: ["a1b", "a1B", "A1b", "A1B"]
Why:    two letters, two choices each, four strings
Input:  s = "3Z"
Output: ["3z", "3Z"]
Why:    the letter's original case does not matter, both forms are listed
Input:  s = "42"
Output: ["42"]
Why:    edge case, with no letters there is exactly one string, the input itself

Hints

0 / 3

Stuck on the idea rather than the code? Subsets covers it.