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
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()];
}Before you run anything, talk me through the approach.
Why group by a sorted key? What does that cost on long strings?
Good. Now the complexity, in terms of total characters.
Featured questions
Browse by format
Arrays, strings, graphs and DP, practised in the coding room with your code watched live.
View problemsThe design questions real loops are built around. The rooms open soon; the question set is final.
View problemsBehavioural and fundamentals questions, answered out loud with follow-ups.
View problemsYour practice record
Loading your sessions...