We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
title:
Debugged and Reliable Python Solution for XOR Strings
Body:
Hi everyone! 👋
I faced an issue where the same code sometimes failed hidden test cases and then passed on retry.(reset your page)
Here’s a clean and robust Python solution for the XOR Strings problem:
Python Code
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().strip()
t = input().strip()
print(strings_xor(s, t))
How it works:
Compare characters of both strings one by one.
If characters are the same → add '0' to the result.
If characters are different → add '1' to the result.
.strip() ensures no extra spaces cause wrong answers.
Return the final XOR string.
✅ This method handles hidden test cases reliably and avoids common issues like extra spaces, leftover debug prints, or newline mismatches.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Problem solving
You are viewing a single comment's thread. Return to all comments →
title: Debugged and Reliable Python Solution for XOR Strings Body: Hi everyone! 👋
I faced an issue where the same code sometimes failed hidden test cases and then passed on retry.(reset your page)
Here’s a clean and robust Python solution for the XOR Strings problem:
Python Code
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().strip() t = input().strip() print(strings_xor(s, t))
How it works:
.strip()ensures no extra spaces cause wrong answers.✅ This method handles hidden test cases reliably and avoids common issues like extra spaces, leftover debug prints, or newline mismatches.