FunctionRacerProblemsRace

Letter Case Variants

EasyRecursionPython, JavaScript, TypeScript, Java, C++

s is a string of lowercase letters and digits. Return every string that can be made from s by choosing, for each letter, whether it stays lowercase or becomes uppercase. Digits never change. Return the variants in any order, each exactly once; a string with no letters has exactly one variant, itself, and the empty string gives [""].

For example, "a1b" gives ["a1b", "a1B", "A1b", "A1B"] in some order.

Example 1

s "a1b"
returns ["a1b","a1B","A1b","A1B"]

Each of the two letters can be lowercase or uppercase, giving 2 * 2 = 4 variants; the digit stays.

Example 2

s "12"
returns ["12"]

There are no letters, so the only variant is the string itself.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems