LeetCode 49. Group Anagrams [Algorithm + Code Explained ] Best Solution

preview_player
Показать описание
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.

LeetCode : Group Anagrams

Question : Given an array of strings, group anagrams together.

Example:

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

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

Note:
All inputs will be in lowercase.
The order of your output does not matter.

Рекомендации по теме
Комментарии
Автор

Where can I find this chart of possible approaches? Can you add a link in the description?
Of course I could just copy it myself but just checking.

jasmine
Автор

I used the same approach in paypal interview and to be honest the interviewer was not satisfied.
Instead a better approach would be to sort all strings in the given array which makes the all anagrams same string. Add all duplicate strings into separate list and return them.

SunilKumar
Автор

I have seen the responses where in people have used Arrays.sort and and used the srorted string as key and created the key-list map. It is accepted in LeetCode but do companies have an issue with this solution?

MrArpit
Автор

@jayati tiwari love your videos so explantive, it would be great if you an share the PPT in the description thanks

ramaseshannarasimha