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.
generate a prime number array of length of 1200 or more to avoid IndexError
Create your answers array i.e answers = [ ]
Your value "q" given in the question is the first loop
So for i in range(q)
Create your "A and B" array A = [] ; B = []
- `
lower = 2; upper = 10_000
prime=[i for i in range(lower, upper + 1) if all(i % j != 0 for j in range(2, i))]
answers = []
for i in range(q):
A = []; B = []
for num in number[::-1]:
if num % prime[i] != 0:
A.append(num)
else:
B.append(num)
answers += B[::-1]
number = A
return answers + number[::-1]`
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 →
*Explaination
Algorithm
answers = [ ]
for i in range(q)
A = [] ; B = []
- `