You are viewing a single comment's thread. Return to all comments →
Here is my solution for this problem(java,javascript)
https://webdev99.com/sparse-arrays-problem-solving-data-structures/
for detailed solution checkout above article
java:
List<Integer> result = new ArrayList<Integer>(); for(int i=0;i<queries.size();i++) result.add(Collections.frequency(strings,queries.get(i))); return result;
Javascript:
var result=[]; let counts={}; for (const str of strings) counts[str] = counts[str] ? counts[str] + 1 : 1; for(var i=0;i<queries.length;i++) if(counts.hasOwnProperty(queries[i])) result.push(counts[queries[i]]); else result.push(0); return result;
result.push(0); return result;```
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 my solution for this problem(java,javascript)
https://webdev99.com/sparse-arrays-problem-solving-data-structures/
for detailed solution checkout above article
java:
Javascript: