Ad
  • Default User Avatar

    That's cool.. but I have the same question that other, why is the reason to sort?

  • Default User Avatar

    The best possible time complexity for this task is linear.
    This implementation has linear-logarithmic time complexity and it also corrupts the initial data.
    Conciseness can never justify poor performance. Sorry, but it's definitely not the best practice.

  • Default User Avatar
    1. You are wrong - to sort primitives Java uses the so-called Dual-Pivot Quicksort. This algorithm is based on quicksort, as obvious from its name, but in fact, comprises many technics to ensure linear-logarithmic performance even with the massive data.

    2. Your solution is computationally intensive as well, it performs iteration through the entire array B for every element in array A. That gives O(n * m) time complexity.
      And this task can be solved in a linear time (try to refine your algorithm, or you may look at my solution).
      Additionally, your code has a side effect - it mutates array B.

  • Default User Avatar

    sort is pretty kind of simplest way but costs too much because it takes O(nlog(n)) for fastest merge sort,but at least,it looks pretty clear and readable,well done!Arr

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Sorting isn't cheap. Isn't there a way to evaluate the efficency of a solution?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution