Generate every uppercase and lowercase variant of a string
Company: Yelp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
Overview: Given a string of letters and digits, return every string you can form by switching each letter between lowercase and uppercase, sorted by character code. The problem tests backtracking or iterative expansion, counting the outputs, and producing them in a deterministic order.
Constraints
- 1 <= len(s) <= 12
- s consists of lowercase English letters, uppercase English letters, and digits.
Examples
Input: ('a',)
Expected Output: ['A', 'a']
Explanation: Minimum length with one lowercase letter: its uppercase form sorts first.
Input: ('Q',)
Expected Output: ['Q', 'q']
Explanation: Single uppercase letter: s itself comes first, then its lowercase form.
Hints
- Each letter position has two choices and each digit has one. How many strings does a given number of letters produce?
- Every result string has the same length as s, so two of them compare at the first position where they differ. At a letter position, which of the two characters comes first?
- Try an input whose letters are already uppercase: s must still appear, along with every lowercase choice.