212. Group Anagrams

MediumStringString

Given an array of strings, group the anagrams together and return the number of distinct anagram groups. Input: a JSON array of strings.

Input: JSON array of strings.

Output: Integer — number of anagram groups.

Examples

Example 1
Input: ["eat","tea","tan","ate","nat","bat"]
Output: 3
Explanation: Groups: {eat,tea,ate},{tan,nat},{bat}.
Example 2
Input: [""]
Output: 1
Explanation: One empty-string group.
Example 3
Input: ["a"]
Output: 1
Explanation: Single group.

Constraints

Asked by

AdobeOracleAmazonAppleDeloitteWipro
Solve this problem in the editor →