What did you try in the attempt in which you got WA? Were you thinking of an efficient approach? I checked the submissions and most of the people have submitted the O(n^2) approach.
im submitting this now , yesterday i didnāt take part only.
can you check if it is correct?.
for all test cases.
I heard this problem has very weak test cases.
Hey. Fine Iāll try to understand your logic.
Yess I was thinking of an effiecient approachā¦
This code got accepted just now.but i want to know if there is some test case for which it doesnāt,as there is more learning in that.
Fine, should have tried to submit the brute force one once lol. Anyways, the n>62 thing is too much for a 2nd question in a cook-off, didnāt expect that kind of complexity. I feel that the O(n^2) approach should have been valid officially from the beginning.
try this one -
1
3
1 50 99
Answer - NO
in my approach , i just sorted the array in decreasing order.
then,
im taking a variable called ans=a[0];
everytime im checking if ans==ans|a[i];
reason:consider 1 2 7
sort in in decreasing order 7 2 1
now ans=7;
7==7|2
hence break.
otherwise make ans=ans|a[i];
but my doubt is does it work for all cases?.
yes i got answer as NO.
Not sure about that. My approach was different.
Very Poorly designed Test cases , NĀ³ passed
can you share your approach?.
@hellaweird even I do now think that I should have tried brute force approachā¦ but the thing is that the hefty penalty in cookoff kept me away from such inefficient brute force approachā¦
Check the editorial, Iāve used the same approach, iterating through the sub-arrays.
okay thank you.
I donāt have that much deep knowledge . But donāt you think those two bit will be same for every Ai.
Can anyone please explain how if there are more than 62 elements, we can always find 2 numbers such that the bits set in one number can be found in another number? If there are exactly 62 elements, is the only case where the answer exists the case where the numbers 1,2,8,16,32,64ā¦2^(61) are the numbers given?
Could anyone suggest me where i am wrong?? Please ā¦
https://www.codechef.com/viewsolution/35812215
Yes, it should CodeChef: Practical coding for everyone
see thisā¦as we know OR is a commutative operator so u can take any array elements and just do or operation u will get distinct values if that result is not present in array
i am bad at solving these bits problem
can anyone plzz tell me any resources to study or how to approach these questions