Group Anagrams
You get a list of words. Put them into groups so that each group holds the words made of the same letters, only in a different order. Our example: [arc, stop, car, pots, rat, tops] — three groups: [arc, car], [stop, pots, tops] and [rat].
- input
strs: an array of strings.- returns
- The strings grouped so that each group holds all the anagrams of one another: the same letters, each as many times. Groups in any order, strings in a group too.
- constraints
- 1 ≤ strs.length ≤ 1000
- 0 ≤ strs[i].length ≤ 100
- strs[i]: lowercase English letters
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string[]} strs
* @return {string[][]}
*/
function groupAnagrams(strs) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more hash map problems
- 1Two SumEasysolve
- 217Contains DuplicateEasysolve
- 242Valid AnagramEasysolve
- 169Majority ElementEasysolve
- 383Ransom NoteEasysolve
- 205Isomorphic StringsEasysolve
- 290Word PatternEasysolve
- 219Contains Duplicate IIEasysolve
- 128Longest Consecutive SequenceMediumsolve
- 36Valid SudokuMediumsolve
- 138Copy List with Random PointerMediumsolve
- 149Max Points on a LineHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.