Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Group Anagrams
00:00
5 left

Group Anagrams

MediumPython

Problem

Given an array of strings, how would you group anagrams?

Implement group_anagrams(strs) to return a list of groups. Each group must contain strings that are anagrams of one another, preserve the input order within the group, and preserve the order in which groups are first encountered. Assume strings contain lowercase English letters only. The input may be empty.

Constraints

  • 0 <= strs.length <= 10^4
  • 0 <= strs[i].length <= 100
  • strs[i] contains only lowercase English letters
  • Return groups in first-encounter order and preserve input order within each group

Function Signature

def group_anagrams(strs):
Interviewer

Your question is Group Anagrams. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.