The company chooses two gates, gateA and gateB, each containing N number of binary strings in their output. To make the gateA-output similar to gateB, they need to find a binary string T such that when XOR of T with each string in gateA output is performed, then the gateB output is similar to that of gateA. If no such string T is possible, then output a blank string.
Write an algorithm to help the company find the string T. If no such string is possible, then output a blank string. If there are multiple strings with the minimum number of 1s, output the lexicographically smallest string. If there are multiple strings with the same number of 1s and the same lexicographical order, output any one of them.
The first line of the input consists of an integer num_gates representing the number of gates.
The second line consists of an integer num_A representing the number of strings in gateA output (N).
The third line consists of num_A space-separated binary strings representing the outputs of gateA.
The last line consists of num_B space-separated binary strings representing the number of strings in gateB output (num_B is equal to N).
Print a string representing the required binary string T. If no such string is possible, print an empty string.
MyKaarma • Pending