Ad
  • Custom User Avatar

    (OP's language was Java) added fixed tests with duplicate elements

  • Custom User Avatar

    Your code does almost the same thing, but manually checks the difference sign and changes it to positive by itself, which adds extra if statements. They can slow things down a bit, especially if the code is executed many times. Math.abs() will work faster. The difference is minimal.