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.
This comment is hidden because it contains spoiler information about the solution
overengineering is fun :P
This comment is hidden because it contains spoiler information about the solution
lodash to the rescue :)
range() works similar to python's range
lodash is awesome :D
range is bae
This comment is hidden because it contains spoiler information about the solution
...who cares? It's just a different way to solve it.
O(digits)
time, same as most other solution except for the brilliantO(1)
math solutionO(1)
space, which is smaller than theO(digits)
space of solutions that convert the number to a string (most solutions).Also, not using recursion saves some space (recursive solutions probably have some kind of
O(log(digits))
space but not 100% sure)None if this really matters though since we're dealing with digits but just included for those who like practicing big O stuff.
O(digits)
timeO(1)
space, which is better than theO(digits)
space of solutions that convert the number to a string.Also, not using recursion saves some space (recursive solutions probably have some kind of
O(log(digits))
space but not 100% sure)None if this really matters though since we're dealing with digits but just included for those who like practicing big O stuff.
Obviously, this is much harder to read and understand than the other solutions, but it runs in O(n) instead of others' O(n * logn) for those that are into that sort of thing. ;)
It basically just compares elements from both arrays and adds the smallest to the result until there's nothing left to look at.
(Updated version that's a little more readable.)
Obviously, this is much harder to read and understand than the other solutions, but it runs in
O(n)
instead of others'O(n * logn)
for those that are into that sort of thing. ;)It basically just compares elements from both arrays and adds the smallest to the result until there's nothing left to look at. Done in one pass through.
Runs in
O(1)
time which is faster than theO(number of digits)
time of the top solution (the one where you convert to a string). Not that much faster in practice because numbers of digits usually never get very big.I'm not saying my solution is better overall, so please no offended replies where you try to defend your ego or something. Don't take it to heart.
https://www.codewars.com/kata/reviews/57090654c8baa14e3700004e/groups/5effbf066dead60001b095d6
Alright, here's the fixed version. It should be
O(1)
now, but my I'm new to js so if there's something wrong let me know.Loading more items...