Bit-By-Bit: Chef and Strange Fear

Janhavi dadhania
The Coding Culture
Published in
2 min readJan 21, 2021

APPROACH :

In case you too were scared like our chef and didn’t read the question during the contest, We encourage you to go back and give it one more try.

Basic Funda to answer is:
a XOR b = c
c XOR a = b
c XOR b = a

Solving by taking an example:

Assume a is 5 and b is 6 i.e the sets chosen by Raj are 5 and 6 and the number of elements in sets are 3 and 4 respectively.

One possible set of values according to the constraint mentioned in the problem statement are
5 = [NAN, ZBV, WER]
6 = [NNA, ZVB, WRE, UUH]

set A, B, C and P are as below.

A = [5, 5, 5]
B = [6, 6, 6, 6]
P = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
C = [5, 5, 5, 6, 6, 6, 6]

Now, we need to find total pairs x,y where x is an element from C and y is an element from P, such that their XOR should be an element of C. With little observation, you will realize that every valid x,y pair satisfies the required condition. Thus, total pairs will be equal to, the number of elements in P multiplied by the number of elements in C.

Note that, every string from set 5(or any set which Raj has), when passed through conversion function returns the same integer, and thus, for every possible set 5 and 6, set A and B remains the same.

SOLUTION :

The solution in c++:

--

--

Janhavi dadhania
The Coding Culture
0 Followers
Writer for

Machine Learning Engineer @ Sharechat & Moj