Difficulty in understand

not able o understand this PS

@kushal1998
According to the problem statement:

There are N stacked cards on pile . Each card has a number written on it. Then there will be Q iterations. In ith iteration, you start picking up the cards in Ai-1th pile from the top one by one and check whether the number written on the card is divisible by the ith prime number. If the number is divisible, you stack that card on pile Bi. Otherwise, you stack that card on pile Ai. After Q iterations, cards can only be on pile B1, B2, B3, . . . BQ, AQ . Output numbers on these cards from top to bottom of each piles in order of B1, B2, B3, . . . BQ, AQ

The sample test case is:
5 1
3 4 7 6 5

Here N is 5 and Q is 1, so we’ve 5 cards and we need to do 1 iteration. So for the 1st iteration, i = 1, and we have to pick up the cards from initial pile A0. A0 has 5 on top, then 6, 7, 4, 3 till bottom. !st prime no(ith prime no) is 2, so we stack the cards divisible by 2 on B1, and not divisible by 2 on A1 after going through the A0 pile. after the 1st iteration,
A1: 5 7 3(top to bottom)
B1: 6 4(top to bottom)
as here Q is 1, orderof displaying will be B1A1
so ans will be 4 6 3 7 5(on first popping elements of B1, then A1
For more than one iteration, keep in mind that for every subsequent iteration, you go through A(i-1)th pile, and print end ans like B1B2B3…BqAq.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.