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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Backtracking
String generation
Branching
Case folding
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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.

...


Submit Your Answer
Markdown supported