In this XOR Strings 3 HackerRank Problem, the task is to debug the existing code to successfully execute all provided test files.
Given two strings consisting of digits 0 and 1 only, find the XOR of the two strings.
To know more about XOR Click Here
Debug the given function strings_xor
to find the XOR of the two given strings appropriately.
Note: You can modify at most three lines in the given code and you cannot add or remove lines to the code.
To restore the original code, click on the icon to the right of the language selector.
Input Format
The input consists of two lines. The first line of the input contains the first string, , and the second line contains the second string, .
Constraints
Output Format
Print the string obtained by the XOR of the two input strings in a single line.
Sample Input
10101
00101
Sample Output
10000
Explanation
The XOR of the two strings and is .
XOR Strings 3 HackerRank Problem Solutions
I will Provide solution in Multiple programming languages for you. If you are not able to find the code in required language then please share in comments so that our team can help you.
Problem Solution in Java 7
public static String stringsXOR(String s, String t) {
String res = new String("");
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == t.charAt(i))
res += "0";
else
res += "1";
}
return res;
}
Problem Solution in Python
def strings_xor(s, t):
res = ""
for i in range(len(s)):
if s[i] == t[i]:
res += '0';
else:
res += '1';
return res
s = input()
t = input()
print(strings_xor(s, t))
Note: XOR String Implementation is possible in only few languages please chose only those languages else you will get errors. Also do not copy the code as the task is just to debug so just try debugging.
Solve original Problem on HackerRank here. Checkout more HackerRank Problems