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 equivelent JavaScript code with comments:
functionpickingNumbers(a){returna.reduce((count,val)=>{// count occurance of each numbercount[val]++returncount;},newArray(100).fill(0)).reduce((max,val,index,count)=>{// max number of integers such that the absolute // difference between any two is 1if(max<val+count[index+1]){max=val+count[index+1];}returnmax;},0);}
Fill an array with zeros
Increment the count for each number found
Find the maximum pair of numbers
It should be noted that you could end up with a subset containing all the same integer.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
Here is the equivelent JavaScript code with comments:
It should be noted that you could end up with a subset containing all the same integer.