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.
functionnonDivisibleSubset(k,s){letremFreq={};letans=0;for(letnofs){remFreq[n%k]=(remFreq[n%k]||0)+1;}// take a single number from all those numbers having rem 0if('0'inremFreq){ans+=1;}// next add up the count of remainder keeping in mind two edge cases for(letrem=1;rem<=Math.floor(k/2);rem++){// take a single number from all having remainder k / 2if(rem===k-rem){ans+=1;}else{// take the max of rem or k - rem ans+=Math.max(remFreq[rem]||0,remFreq[k-rem]||0);}}returnans;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Non-Divisible Subset
You are viewing a single comment's thread. Return to all comments →