# MYSARA March COOK OFF didn't understand the question

plz explain how the sequence B is generated with the help of A.i did’nt understand how Bi was calculated

Watch this:

Assume that A1, A2, A3 … An is known.
So
B1 = A1
B2 = A1 | A2
B3 = A1 | A2 | A3
.
.
Bn = A1 | A2 | A3 … | An

1 Like

What after then, how sample test cases are generating the given sample outputs???

Sample Test Case :

``````2
2
2 3
4
2 6 7 7
``````

For the second test case i.e. `2 6 7 7`, binary equivalents are
B1 = 10
B2 = 110
B3 = 111
B4 = 111
Now,
B1 = A1 = 10 —> 1 choice only
B2 = A1 | A2 = 110
= 010 | A2 = 110
A2 can be 100 or 110 —> 2 choices
ans so on …

As you noticed that,
Bi = Bi-1 | Ai ----> `Ai can select/reject any set bits of Bi-1`

So Answer = ways of selecting ( A1 ) * ways of selecting ( A2 ) … * ways of selecting (An)
which is equivalent to
Answer = 1 * (2 ^ set bits of B1) * (2 ^ set bits of B2) * … * (2 ^ set bits of Bn-1)

2 Likes

Thank you @codinginveins, i got it how it is giving the answer as required. And also got the and check part to validate if the given B array is valid or not .

2 Likes