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.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'nonDivisibleSubset' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. INTEGER k# 2. INTEGER_ARRAY s#defnonDivisibleSubset(k,s):# Write your code herefreq_of_rem=[0foriinrange(k)]fornumins:freq_of_rem[(num%k)]+=1print(freq_of_rem)result=0if(freq_of_rem[0]>=1):result+=1if(k%2==0):foriinrange(1,(k//2)):result+=max(freq_of_rem[i],freq_of_rem[(k-i)])result+=min(1,freq_of_rem[k//2])else:foriinrange(1,(k//2)+1):result+=max(freq_of_rem[i],freq_of_rem[(k-i)])print(result)returnresultif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')first_multiple_input=input().rstrip().split()n=int(first_multiple_input[0])k=int(first_multiple_input[1])s=list(map(int,input().rstrip().split()))result=nonDivisibleSubset(k,s)fptr.write(str(result)+'\n')fptr.close()
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 →