We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi! This was my attempt using Javascript. I think its o(n) time or o(n+q) technically. I could probably avoid storing them in arrays in the groupedStrings array in hindsight
functionmatchingStrings(strings,queries){// Write your code hereconstgroupedStrings={};strings.forEach((string)=>{if(!groupedStrings[string]){groupedStrings[string]=[]}groupedStrings[string].push(string);})queries.forEach((query)=>{if(groupedStrings[query]==undefined){console.log(0);return;}console.log(groupedStrings[query].length);})}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Hi! This was my attempt using Javascript. I think its o(n) time or o(n+q) technically. I could probably avoid storing them in arrays in the groupedStrings array in hindsight