Leetcode 784: Letter Case Permutation

grid47
grid47
Exploring patterns and algorithms
Aug 20, 2024 6 min read

A string where letter case permutations are made, with each new permutation softly glowing as it’s generated.
Solution to LeetCode 784: Letter Case Permutation Problem

Given a string s, you can transform every letter individually to either lowercase or uppercase. Digits remain unchanged. Your task is to generate a list of all possible strings that can be created by changing the case of the letters in the string.
Problem
Approach
Steps
Complexity
Input: The input consists of a string s that contains lowercase English letters, uppercase English letters, and digits.
Example: Input: s = 'xYz1'
Constraints:
• 1 <= s.length <= 12
• s consists of lowercase English letters, uppercase English letters, and digits.
Output: Return a list of all possible strings that can be created by changing the case of the letters in the input string.
Example: Output: ['xYz1', 'xYz1', 'XyZ1', 'XyZ1', 'xYZ1', 'xYZ1', 'XYz1', 'XYz1']
Constraints:
• The output list contains all the possible case variations of the letters in the input string.
Goal: The goal is to generate all possible case combinations for each letter in the input string.
Steps:
• Iterate over the string s and for each character, generate both the lowercase and uppercase versions if it is a letter.
• For digits, keep them unchanged.
• Use backtracking or recursive techniques to explore all possible combinations.
Goal: The input string will contain up to 12 characters, and each character is either a letter or a digit.
Steps:
• 1 <= s.length <= 12
• The string contains only lowercase letters, uppercase letters, or digits.
Assumptions:
• The input string will not be empty and will contain at least one character.
Input: Example 1: Input: s = 'xYz1'
Explanation: The string contains both uppercase and lowercase letters. We can change each letter to either uppercase or lowercase, generating all the possible combinations of these case changes.

Input: Example 2: Input: s = '9aB'
Explanation: In this case, digits remain unchanged, while the letters 'a' and 'B' can be transformed to 'A' and 'b' or 'a' and 'B', respectively. Therefore, we generate all combinations of the letter cases.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus