Ad
  • Custom User Avatar

    Also, there are method to copy the whole object.

    And also, that's not actually an issue.

  • Default User Avatar

    Sorting the array is a very inefficient way of solving the problem. Folks in the comments pointed out that sorting takes O(n log n) time. The better solution takes O(n) time.

  • Default User Avatar

    someone please tell me why test fail?
    Time: 382ms Passed: 10 Failed: 100
    should work for basic tests (5 Passed, 0 Failed)
    should work for more fixed tests as well (5 Passed, 0 Failed)
    should finally work for random tests
    ✘ Expected: 72, instead got: 61
    ✘ Expected: 90, instead got: 34
    ✘ Expected: 150, instead got: 94
    ✘ Expected: 79, instead got: 17
    ✘ Expected: 31, instead got: 8
    ✘ Expected: 96, instead got: 45
    ✘ Expected: 72, instead got: 53
    ✘ Expected: 157, instead got: 110
    ✘ ...

  • Custom User Avatar

    "Hint: Do not modify the original array."
    What? Array is an object and copying it to the new array just copy the link, so sorting a new array is modify original array. So what was meant in that hint?