← Back to challenges

Generate Different Strings

JavaScriptHardalgorithmsconditionsloopsstrings

Instructions

The function is given a string consisting from letters and digits. Each letter in the string can be changed to lower-case and upper-case; the digits stay as they are in their positions. Generate all possible strings and return them as an array.

Examples

genStrings("1A2") ➞ ["1A2", "1a2"]

genStrings("a1B") ➞ ["A1B", "A1b", "a1B", "a1b"]

genStrings("1a2bC3") ➞ ["1A2Bc3", "1a2Bc3", "1a2bC3", "1a2bc3", "1A2bC3", "1A2BC3", "1a2BC3", "1A2bc3"]

genStrings("1") ➞ ["1"]

genStrings("") ➞ [""]

Notes

Return the sorted Array.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.