Can anyone review my python code?

Link to the prob:

https://www.codechef.com/viewsolution/35809853

This pic has the same code with comments included:

Can anyone review my python code?

Link to the prob:

https://www.codechef.com/viewsolution/35809853

This pic has the same code with comments included:

one observation is if the value of n is greater than 65,ans is NO

because every next element must add one bit to the or of the prefix,

so max 64+1(for 0) is the possible value of n;

you can brute force on this and it is sufficient

but if you do it for n as large as 10^5,you will surely get tle(which is not necessary)as you are doing o (n^2) method

1 Like

I think you can print value of each pairwise or and counter check with sample cases to check if any case is missing.I don’t code in python but when i printed the values of add in your program i got two 7s instead of 3 in first sample case.

1 Like

I’ve got all the sample cases right. In first sample case:

1 3 7

the add values in my code would be the combinations for:

[1] [1 2] [1 2 7] [2 ] [2 7] and [7] which are 1,3,7,2,7,7…

It prints 1,3,7,2 and then 7 and then NO.

Thanks for looking into it anyway.

Actually the program has nothing to interfere with bitwise OR operator right?

I python looks after it by itself.

I understood the TLE part though.

But I’m getting WA.

I’ve checked the editorial…Got it