Anagram grouping of product SKUs
Python data engineering interview problem. Difficulty: intermediate. Pattern: Hashing. About 15 minutes. Part of the Pro drill bank.
Warehouse SKUs are sometimes anagrams of each other (same letters, different order) because of a packing glitch. Group SKUs that share a letter signature.
A catalog has SKU codes that are anagrams of each other (the same letters in a different order), and merchandising wants to group them. Group the SKUs that are anagrams. Sort the SKUs inside each group alphabetically, and sort the groups by their first SKU. Return a list of lists. Write group_anagram_skus(skus). For ['eat','tea','tan'] the result is [['eat', 'tea'], ['tan']]. An empty list gives []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Two SKUs are in a group if they have the same letters.
- Sort the SKUs inside each group.
- Sort the groups by their first SKU.
- Return a list of lists.
Constraints
- skus is a list of strings.
- Each SKU appears in exactly one group.
Examples
Input: group_anagram_skus(['eat', 'tea', 'tan']) Output: [['eat', 'tea'], ['tan']] This input follows the stated rules and produces this output.
Topics: lakebench, python, hash-based-problems.
More Python interview questions · All interview problems · Learn data engineering
Anagram grouping of product SKUs
Interview-style drill: Group SKU codes that are letter-for-letter anagrams of each other.
Group product SKUs that are anagrams of one another.