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.
functionmissingNumbers(arr:number[],brr:number[]):number[]{// convert all of arr to arrMapconstarrMap=newMap();letshifted;while(arr.length){shifted=arr.shift();arrMap.set(shifted,(arrMap.get(shifted)||0)+1);}constdiff=newSet<number>();// remove any brr that matches in arrMap,// then remove from arrMap and brr// any non matches, save in diffwhile(brr.length){shifted=brr.shift();if(arrMap.has(shifted)){arrMap.set(shifted,arrMap.get(shifted)-1);if(arrMap.get(shifted)===0){arrMap.delete(shifted);}}else{diff.add(shifted);}}// diff is prefiltered and just needs to be sortedreturnArray.from(diff).sort((a,b)=>a-b);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Missing Numbers
You are viewing a single comment's thread. Return to all comments →
Typescript: