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.
Javascript Solution:
Loop within the a array with each number using filter to get the numbers that >= 0 or <=1 then get the longest array length
functionpickingNumbers(a){// Write your code hereletnewArr=[]letarLength=0for(leti=0;i<a.length;i++){newArr=a.filter((b)=>a[i]-b>=0&&a[i]-b<=1)if(arLength<newArr.length)arLength=newArr.length}returnarLength}
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 →
Javascript Solution: Loop within the a array with each number using filter to get the numbers that >= 0 or <=1 then get the longest array length