Letter Case Permutation
Real-world version: Every Spelling of a Part CodeThe statement here is our own: the same inputs, outputs and technique.
A warehouse scanner reads part codes made of English letters and digits, and it ignores letter case, so the same part code can be keyed in more than one way.
Return every spelling of code that can be produced by choosing, independently for each letter, whether that letter is written in uppercase or in lowercase. Digits are copied over unchanged.
The spellings may be returned in any order, and each distinct spelling must appear exactly once.
Examples
Example 1
- Input
- code = "p4q"
- Output
- ["p4q", "p4Q", "P4q", "P4Q"]
Two letters each have two cases, so four spellings come out, and the digit 4 stays put in every one of them.
Example 2
- Input
- code = "58"
- Output
- ["58"]
There is no letter to choose a case for, so the code has exactly one spelling, itself.
Example 3
- Input
- code = "Wz"
- Output
- ["wz", "wZ", "Wz", "WZ"]
Each of the two letters is written either way, whatever case it arrived in, giving four spellings.
Constraints
- 1 <= code.length <= 12
- code consists of lowercase English letters, uppercase English letters and digits.
The values you return may be in any order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def code_spellings(code: str) -> list[str]:public List<String> codeSpellings(String code)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Maximum Length of a Concatenated String with Unique CharactersReal-world version: Longest Stencil Run Without A Repeated LetterMedium
- Maximum Score Words Formed by LettersReal-world version: Best Tile Rack PlayHard
- Stickers to Spell WordReal-world version: Cutting Letters Out of StencilsHard
- Add BinaryReal-world version: Combined Toggle RowEasy