You are viewing a single comment's thread. Return to all comments →
Here's my solution following the best possible Big O notation:
function SparseArray(S, Q) { let ob = {} let result = [] for (let i = 0; i < S.length; i++) { ob[S[i]] = (ob[S[i]] || 0) + 1; } Q.forEach(e => { result.push(ob[e] || 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's my solution following the best possible Big O notation: