Practice the interview before it counts

Mock Room runs live voice and coding interviews with Maya or Rohan, using real questions from the companies you are targeting. Every session is scored out of 10, with feedback that names what to fix.

44 problems · 24 companies · free to use

Technical interviewGroup Anagrams · Medium

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

function groupAnagrams(strs) {
  const map = new Map();
  for (const s of strs) {
    const key = s.split("").sort().join("");
    if (!map.has(key)) map.set(key, []);
    map.get(key).push(s);
  }
  return [...map.values()];
}
M
Maya

Before you run anything, talk me through the approach.

M
Maya

Why group by a sorted key? What does that cost on long strings?

M
Maya

Good. Now the complexity, in terms of total characters.

Featured questions

View all 44 problems
Two Sum
Easy
Start
Group Anagrams
Medium
Start
LRU Cache
Medium
Start
Design a Typeahead Suggestion Service
Start
Design a URL Shortener
Start
What happens when you type a URL into a browser?
Medium
Start

Browse by format

Your practice record

Loading your sessions...