![]() |
VOOZH | about |
Given two binary strings A and B of equal lengths, the task is to print a string that is the XOR of Binary Strings A and B.
Examples:
Input: A = "0001", B = "0010"
Output: 0011Input: A = "1010", B = "0101"
Output: 1111
Approach: The idea is to iterate over both the string character by character and if the character is mismatched then add "1" as the character in the answer string otherwise add "0" to the answer string to generate the XOR string.
👁 Image
Below is the implementation of the above approach:
0111
Time Complexity: O(N)
Auxiliary Space: O(N)
Approach: We take two binary strings A and B as input which are of equal length, and apply for loop and performs XOR operation bit by bit to generate the XOR result. Then we print the XOR result string.
Below is the implementation of the above approach:
0111
Time Complexity: O(N)
Auxiliary Space: O(N)