Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The number of results for
n
is ( on the order of )n^2
- in that sense, you're just not going to find anO(n)
solution.In terms of requested number of results, it can be done in
O(n)
. You can't be calculatingn over k
for every result to do that, but following the description works.If iterating over
n
items inO(1)
time were possible, solving P problems would be a lot faster.I'm curious too.
@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.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...
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.
There is no issue with the kata, if you're using sort, it's not stable in javascript and that could be your problem.
It can be done with a single loop
I assure you, codewars returns
NO
for this test... are you doing a dry run off codewars?this test does return
NO