Ad
  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    In operators:
    if (a[i] != b[j]) {
    difference.add(a[i]);
    You output element a[i] as many times as it does not match the elements b. And it must be equal to 1 time, and then only if it does not coincide with any of the elements b.

  • Custom User Avatar
  • Default User Avatar

    When your result looks like the expected one, but still fails, it is helpful to print your string between delimiters and escape whitespace characters.

    For your situation:

    String s = sb.toString();
    System.out.print('"');
    for (int i = 0; i < s.length(); i++) {
        char ch = s.charAt(i);
        System.out.print(ch == '\n' ? "\\n" : Character.toString(ch));
    }
    System.out.print('"');
    

    for n = 1, this prints:

    "*\n \n"

    while the expected answer is:

    "*\n"