Largest Length Product of Two Product Tags With No Shared Letters
Last updated: November 29, 2026
Quick Overview
Sellers attach lowercase keyword tags to listings. Find two tags that have no letter in common and maximize the product of their lengths, returning 0 if no such pair exists.
Amazon
November 29, 20260
0
0 solved
Sellers attach lowercase keyword tags to listings. Find two tags that have no letter in common and maximize the product of their lengths, returning 0 if no such pair exists.
An Amazon onsite question set in the catalog domain. The interviewer expects you to replace the per-pair character comparison with a 26-bit mask per tag so the pair check is a single AND.
What the Interviewer Expects
- Encodes each tag as a 26-bit letter mask
- Checks disjointness with mask_a & mask_b == 0
- Deduplicates masks keeping the longest length
- Analyzes O(n^2 + total length)
- Returns 0 when nothing qualifies
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
- Can you do better than O(n^2) pairs when n is large?
- What if tags can contain Unicode characters?
- Return the actual pair, not just the product.
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: list of lowercase strings. Output: max of len(a) * len(b) over pairs with no common letter; 0 if none. Up to about 1000 tags of up to 1000 characters....
High-Level Design
Comparing two strings letter by letter costs O(L) per pair. Precompute a mask per tag where bit c is set if letter c appears; two tags are disjoint exactly when their masks AND to zero. Many tags shar...