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.
Here is the typescript solution for the better time complexity and space complexity. The time complexity over here will be o(n + q). I have created a hash map for the faster retrival of the information:
Typescript:
functionmatchingStrings(strings:string[],queries:string[]):number[]{// Write your code hereconststringsFreq:{[key:string]:number}={};for(constsofstrings){stringsFreq[s]=(stringsFreq[s]||0)+1;}returnqueries.map(q=>stringsFreq[q]||0);}
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 →
Here is the typescript solution for the better time complexity and space complexity. The time complexity over here will be o(n + q). I have created a hash map for the faster retrival of the information: Typescript: