Ad
  • Custom User Avatar

    The number of results for n is ( on the order of ) n^2 - in that sense, you're just not going to find an O(n) solution.

    In terms of requested number of results, it can be done in O(n). You can't be calculating n over k for every result to do that, but following the description works.

    If iterating over n items in O(1) time were possible, solving P problems would be a lot faster.

  • Default User Avatar

    I'm curious too.

  • Default User Avatar

    @Chrono79 .sort Is not stable in Node v8 and v10, but it's stable in Node 12 and up. Now it's a kata problem for not enabling Node v12.

  • Custom User Avatar

    arr.length is a property of Array.prototype and the kata prohibited Array.prototype methods. And I agree with you, so many solutions are using temp array, the worse is that they are marked as clever...

  • Custom User Avatar

    Please check if you can find anything helpful in this FAQ and if you tried everything and still no success, please share your code with us so we could take a look (remember about markdown formatting and spoiler flag). It is possible that there is some issue in the kata, but since you are the first one to report such problem, I somehow do not think it's really the case here.

  • Custom User Avatar

    There is no issue with the kata, if you're using sort, it's not stable in javascript and that could be your problem.

  • Default User Avatar

    It can be done with a single loop

  • Custom User Avatar

    I assure you, codewars returns NO for this test... are you doing a dry run off codewars?

  • Custom User Avatar

    this test does return NO