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.
def nonDivisibleSubset(k, s):
# Write your code here
s = [i % k for i in s]
freq = {i: 0 for i in range(k)}
for i in s:
freq[i] += 1
ans = 0
for i in range(1, floor(k/2)+1):
if i == k/2:
continue
if freq[i] >= freq[k-i]:
del freq[k-i]
ans += freq[i]
else:
del freq[i]
ans += freq[k-i]
if k/2 in freq and freq[k/2] != 0:
ans += 1
if freq[0] != 0:
ans += 1
return ans
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 →
Python 3
from math import floor
def nonDivisibleSubset(k, s): # Write your code here