Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Group Anagrams

Python data engineering interview problem. Difficulty: beginner. Pattern: Hashing. About 10 minutes. Free to practice.

Group strings that are anagrams; sort groups and group order. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement group_anagrams(strs: list[str]) -> list grouping anagrams. Within each group, sort strings ascending. Sort groups by their first element.

Requirements

  • Inner lists sorted ascending.

Constraints

  • Outer list sorted by first element of each group.

Examples

Input: group_anagrams(['eat','tea','tan','ate','nat','bat']) Output: [['ate', 'eat', 'tea'], ['bat'], ['nat', 'tan']] Groups keyed by sorted letters.

Topics: lakebench, python, anagram, grouping.

More Python interview questions · All interview problems · Learn data engineering

beginner

Group Anagrams

Interview-style drill: Group strings that are anagrams; sort groups and group order.

Implement `group_anagrams(strs: list[str]) -> list` grouping anagrams. Within each group, sort strings ascending. Sort groups by their first element. Example: `['eat','tea','tan','ate','nat','bat']` → `[['ate','eat','tea'],['bat'],['nat','tan']]`. Keep the harness.