You are given an array of strings. Your task is to group all strings that are anagrams of each other. The groups should be formed in the order of their first appearance in the original array.
Note: The final output will be in lexicographic order.
Example 1
Input: arr[] = ["act", "god", "cat", "dog", "tac"]
Output: [["act", "cat", "tac"], ["god", "dog"]]
Explanation: There are 2 groups of anagrams "god", "dog" make group 1. "act", "cat", "tac" make group 2
Example 2
Input: arr[] = ["no", "on", "is"]
Output: [["is"],["no", "on"]]
Explanation: There are 2 groups of anagrams "is" makes group 1. "no", "on" make group 2.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
act god cat dog tac
act cat tac , god dog ,
no on is
is , no on ,
listen silent enlist abc cab bac rat tar art
abc cab bac , listen silent enlist , rat tar art ,