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.
"I've been working on the function and encountered an issue that I haven't been able to resolve. Here's the code I'm using:
Java 7
public class Solution {
public static String stringsXOR(String s, String t) {
StringBuilder res = new StringBuilder(); // Use StringBuilder for efficient concatenation
for (int i = 0; i < s.length(); i++) {
// Calculate XOR for each pair of characters
res.append(s.charAt(i) ^ t.charAt(i));
}
return res.toString().trim();
}
public static void main(String[] args) {
String s, t;
Scanner in = new Scanner(System.in);
s = in.nextLine();
t = in.nextLine();
System.out.print(stringsXOR(s, t));
It passes basic test cases manually, but when running in the environment, it fails with a 'Wrong Answer' message.
I can't figure out where the issue lies, as both the outputs seem the same. If anyone can provide insights or point out anything I might have missed, I'd really appreciate the help. Thanks in advance!"
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
XOR Strings 2
You are viewing a single comment's thread. Return to all comments →
"I've been working on the function and encountered an issue that I haven't been able to resolve. Here's the code I'm using:
Java 7
public class Solution {
It passes basic test cases manually, but when running in the environment, it fails with a 'Wrong Answer' message.
I can't figure out where the issue lies, as both the outputs seem the same. If anyone can provide insights or point out anything I might have missed, I'd really appreciate the help. Thanks in advance!"
}