XOR Strings 2

Sort by

recency

|

250 Discussions

|

  • + 1 comment

    I tried to submit the following method: public static void main(String args[] ) throws Exception { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String s = bufferedReader.readLine(), t = bufferedReader.readLine(); System.out.println(IntStream.range(0, s.length()).mapToObj(i -> String.valueOf(s.charAt(i) ^ t.charAt(i))).collect(Collectors.joining()));

    } although it visually presents the same result. It is difficult to understand what the real problem is.

  • + 0 comments

    I have checked multiple times, my logic is correct, the output I am printing is also correct but compiler says wrong answer. Any idea? Compiler Message: Wrong Answer Input (stdin) 10101 00101 Your Output (stdout) 10000 Expected Output 10000

  • + 0 comments

    C++ test:

    do not refactor, just fix three errors. There is a bug somewhere on test backend, it fails tests if submitted under C++20/C++23. If submitted under C++14, it passes all tests. It is a bug on the HR backend, the same code compiled under gcc with C++20 compliance works just fine.

  • + 0 comments

    for java user 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"; } use this code it will clear as the note in problem suggest to to not delete or add code annd only 3 changes so this will help as i cleared return res; }

  • + 2 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 {

    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!"

    }
    

    }