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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
bitmask
set disjointness
hashing
pairwise search
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported