• + 0 comments

    Python 3

    from math import floor

    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