Codeforces question

https://codeforces.com/problemset/problem/1362/B

Sir above is the link of the problem and sir I am not understanding this below editorial please clear me this sir

Editorial -

Consider i-th least significant bit (0 indexed). If it is set in k, but not in s, it will be set in k⊕s. Hence k⊕s≥2i.

Consider such minimal positive integer m, that 2m>s holds for all s∈S. k cannot have the i-th bit set for any i≥m. From this follows that k<2m. So there are only 2m feasible choices of k. We can verify if a number satisfies the condition from the statement in O(n) operations. This gives us a solution with complexity O(n⋅2m). Note that in all tests m is at most 10.

There is also another solution possible. It uses the observation that if k satisfies the required conditions, then for every s∈S there exists such t∈S (t≠s) , that t⊕s=k. This gives us n−1 feasible choices of k and thus the complexity of this solution is O(n2)

hello @yashme7125

they first determine the upper limit of k.
and then they simply brute force on values in range [0…upper limit] to find k which satisfy the given property.

upper limit -> 2^i where i is the highest set bit position in given numbers.

Thanks sir for explaining this.

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.