Generate Every Capitalization Variant of a Product Code
Last updated: November 29, 2026
Quick Overview
Given a product code made of letters and digits, return every string obtainable by switching each letter to lowercase or uppercase independently. Digits stay as they are.
0
0
0 solved
Given a product code made of letters and digits, return every string obtainable by switching each letter to lowercase or uppercase independently. Digits stay as they are.
A quick Google phone-screen problem, framed as testing a case-insensitive lookup in a Google Shopping catalog. The interviewer checks clean branching only on letters and the 2^L output size where L is the number of letters.
What the Interviewer Expects
- Branches only on letters, passing digits straight through
- Builds strings with a list and undo, or an iterative doubling approach
- States O(2^L * n) where L is the letter count
- Handles a code with no letters
- Mentions why a case-insensitive index is the better production fix
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return only variants with at most two uppercase letters?
- Write the iterative doubling version.
- How would you index codes so lookups are case-insensitive without enumerating variants?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: string of letters and digits, for example
"a1b2". - Output: every case variant:
a1b2,a1B2,A1b2,A1B2. - Order does not matter....
High-Level Design
Walk the string. At a digit there is one choice, so append it and move on. At a letter there are two choices: append its lowercase form and recurse, then replace with the uppercase form and recurse.
...