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.
So I think the hardest part was trying to find the prime numbers, I eventually found an algorithm called "The Sieve of Eratosthenes" and it worked, but would time out in some cases. Then realized we only need to determine prime numbers up to the maximum value of the numbers. So if the array of prime numbers is smaller than K, well everything just goes into Stack A always, for anything past the prime array.
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 →
So I think the hardest part was trying to find the prime numbers, I eventually found an algorithm called "The Sieve of Eratosthenes" and it worked, but would time out in some cases. Then realized we only need to determine prime numbers up to the maximum value of the numbers. So if the array of prime numbers is smaller than K, well everything just goes into Stack A always, for anything past the prime array.