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.
In the comments section was my first solution but the execution time was too long.
defnonDivisibleSubset(k,s):# import itertools# for r in range(len(s), 0, -1):# for c in itertools.combinations(s, r):# if all(sum(comb) % k != 0 for comb in itertools.combinations(c, 2)):# return len(c)# return 0 fromcollectionsimportCounterfreq=Counter(num%kfornumins)count=min(freq.get(0,0),1)foriinrange(1,(k// 2) + 1):ifi==k-i:count+=1else:count+=max(freq.get(i,0),freq.get(k-i,0))returncount
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 →
In the comments section was my first solution but the execution time was too long.