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.
Hints:
- As you're reading the input, you're building the initial stack.
- Then you start taking plates off that to build the next two stacks. In each step you're turning just one stack into two new stacks.
- When printing a stack you print from top to bottom, like you're feeding the plates into the printer.
- Ignore the part about how many stacks (Q or Q+1) you end up with. If none of the numbers is divisible by a particular prime, that leaves a stack out. If all of the numbers remaining are divisible by the next prime, it ends the process early. So the Q or Q+1 claim is generally wrong.
- Google "free-online-calculator-use prime-number-generator" for an easy form-based way to generate the first 1200 primes (it starts with 2, so you just need to tell it 1200) with commas and spaces so you can just paste it into an initializer.
- The hard part of this problem is understanding the problem statement. After that it's straighforward popping and pushing (and some allocation/deallocation or juggling of the stacks, if you don't want to generate 1200 stacks before you print the first -- it won't make a difference in memory, since when you pop from one stack and push in another the total number of plates stays constant). If it had been presented better it would be an easy problem, except for the prime numbers, which aren't the point of the problem. It doesn't even have unreasonable time constraints that would force hacking around slow standard-library stack classes. It would have had way more than a 60% success rate if it were more clear.
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 →
Hints:
- As you're reading the input, you're building the initial stack.
- Then you start taking plates off that to build the next two stacks. In each step you're turning just one stack into two new stacks.
- When printing a stack you print from top to bottom, like you're feeding the plates into the printer.
- Ignore the part about how many stacks (Q or Q+1) you end up with. If none of the numbers is divisible by a particular prime, that leaves a stack out. If all of the numbers remaining are divisible by the next prime, it ends the process early. So the Q or Q+1 claim is generally wrong.
- Google "free-online-calculator-use prime-number-generator" for an easy form-based way to generate the first 1200 primes (it starts with 2, so you just need to tell it 1200) with commas and spaces so you can just paste it into an initializer.
- The hard part of this problem is understanding the problem statement. After that it's straighforward popping and pushing (and some allocation/deallocation or juggling of the stacks, if you don't want to generate 1200 stacks before you print the first -- it won't make a difference in memory, since when you pop from one stack and push in another the total number of plates stays constant). If it had been presented better it would be an easy problem, except for the prime numbers, which aren't the point of the problem. It doesn't even have unreasonable time constraints that would force hacking around slow standard-library stack classes. It would have had way more than a 60% success rate if it were more clear.