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.
functionplayingWithNumbers(arr,queries){// Write your code hereletsum=0;letother=[];arr.forEach(n=>{if(n<-2000||n>2000){sum+=Math.abs(n);}else{other[n+2000]=(other[n+2000]||0)+1;}});letxx=0;returnqueries.map(x=>{xx+=x;returnother.reduce((acc,c,n)=>acc+Math.abs(n-2000+xx)*c,sum);});}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Absolute Element Sums
You are viewing a single comment's thread. Return to all comments →
JavaScript solution