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.
Although the problem demands a stack to achieve this, I was able to use only the concept of stack without actually juggling the numbers between stacks. I used a boolean array to keep track of numbers that are already printed and a flag to toggle the direction that I traverse the array every time - this helped me achieve the push/pop order. I could visualize this problem as eliminating all numbers divisible by ith prime in iteration 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 →
Although the problem demands a stack to achieve this, I was able to use only the concept of stack without actually juggling the numbers between stacks. I used a boolean array to keep track of numbers that are already printed and a flag to toggle the direction that I traverse the array every time - this helped me achieve the push/pop order. I could visualize this problem as eliminating all numbers divisible by ith prime in iteration i.