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
ans = 0
if k == 1:
return 1
else:
remainder_list = [[0] for i in range(k)]
for i in s:
remain = i % k
remainder_list[remain][0] += 1
if remainder_list[0][0] != 0:
ans += 1
for i in range(1,k//2):
ans += max(remainder_list[i][0], remainder_list[k-i][0])
if k % 2:
ans += max(remainder_list[k//2][0], remainder_list[k-k//2][0])
else:
if remainder_list[k//2][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 →
Python3 solution:
def nonDivisibleSubset(k, s): # Write your code here ans = 0 if k == 1: return 1 else: remainder_list = [[0] for i in range(k)] for i in s: remain = i % k remainder_list[remain][0] += 1