PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string-processing and data-structuring competency, focusing on identifying and grouping anagrams through comparison of unordered character multisets.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Group strings that are anagrams

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an array of strings, group the strings into lists such that each list contains strings that are anagrams of each other. ## Definition Two strings are anagrams if they contain the same characters with the same frequencies (order does not matter). ## Input - `strs`: an array of strings (assume lowercase English letters). ## Output - Return a list of groups, where each group is a list of anagram strings. - The order of groups does not matter. The order of strings within a group does not matter. ## Example Input: `[ "eat", "tea", "tan", "ate", "nat", "bat" ]` Output (one valid answer): `[ ["eat","tea","ate"], ["tan","nat"], ["bat"] ]` ## Constraints (assumed) - `1 <= len(strs) <= 10^4` - `0 <= len(strs[i]) <= 100` - Total characters across all strings `<= 10^6`

Quick Answer: This question evaluates string-processing and data-structuring competency, focusing on identifying and grouping anagrams through comparison of unordered character multisets.

Given an array of lowercase English strings, group the strings so that each group contains words that are anagrams of one another. Two strings are anagrams if they contain exactly the same characters with the same frequencies, regardless of order. Any grouping order is logically valid, but for deterministic evaluation in this problem, return each group sorted lexicographically, and then sort the list of groups by the first string in each group.

Constraints

  • 1 <= len(strs) <= 10^4
  • 0 <= len(strs[i]) <= 100
  • The total number of characters across all strings is <= 10^6

Examples

Input: (["eat", "tea", "tan", "ate", "nat", "bat"],)

Expected Output: [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]

Explanation: "eat", "tea", and "ate" are anagrams; "tan" and "nat" are anagrams; "bat" stands alone. Groups and words are sorted for deterministic output.

Input: (["", "", "a"],)

Expected Output: [["", ""], ["a"]]

Explanation: The two empty strings are anagrams of each other, and "a" forms its own group.

Input: (["abc"],)

Expected Output: [["abc"]]

Explanation: A single string forms one group by itself.

Input: (["abc", "bca", "cab", "foo", "ofo", "bar", "abc"],)

Expected Output: [["abc", "abc", "bca", "cab"], ["bar"], ["foo", "ofo"]]

Explanation: All versions of "abc" belong together, "foo" and "ofo" are anagrams, and "bar" is alone.

Hints

  1. Anagrams share the same character signature. Think about how to turn each word into a key that will be identical for all its anagrams.
  2. Because the strings only contain lowercase English letters, a 26-length frequency count can be used as a hashable grouping key.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)