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.
For Q = 2, you will have two prime numbers, 2 and 3. Let's say there are 10 plates, numbered randomly.
1 8 11 23 18 2 15 30 4 5
After the first step, you will have split this pile into two piles (shown from top to bottom, since they are pushdown stacks), the first containing all the plates with numbers divisible by 2 (the first prime number).
4 30 2 18 8
5 15 23 11 1
Then the second pile is split into two piles based on whether they are divsible by 3 (the second prime number) and the three piles look like
4 30 2 18 8
15
1 11 23 5
You print these top to bottom, first to last, and the printout looks like
4 30 2 18 8 15 1 11 23 5
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 →
For Q = 2, you will have two prime numbers, 2 and 3. Let's say there are 10 plates, numbered randomly.
1 8 11 23 18 2 15 30 4 5
After the first step, you will have split this pile into two piles (shown from top to bottom, since they are pushdown stacks), the first containing all the plates with numbers divisible by 2 (the first prime number).
4 30 2 18 8
5 15 23 11 1
Then the second pile is split into two piles based on whether they are divsible by 3 (the second prime number) and the three piles look like
4 30 2 18 8
15
1 11 23 5
You print these top to bottom, first to last, and the printout looks like
4 30 2 18 8 15 1 11 23 5