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 'waiter' function below.## The function is expected to return an INTEGER_ARRAY.# The function accepts following parameters:# 1. INTEGER_ARRAY number# 2. INTEGER q#defgenerate_primes(q):primes=[]num=2whilelen(primes)<q:is_prime=Trueforpinprimes:ifnum%p==0:is_prime=Falsebreakifis_prime:primes.append(num)num+=1returnprimesdefwaiter(arr_p,q):primes=generate_primes(q)answers=[]foriinrange(q):A,B=[],[]prime=primes[i]whilearr_p:plate=arr_p.pop()ifplate%prime==0:B.append(plate)else:A.append(plate)answers.extend(reversed(B))arr_p=Aanswers.extend(reversed(arr_p))returnanswersif__name__=='__main__':n,q=map(int,input().split())arr_p=list(map(int,input().split()))result=waiter(arr_p,q)foriinresult:print(i)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Waiter
You are viewing a single comment's thread. Return to all comments →
Solution in Python