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.
I guess it's better to just saying it in words: this loops over the input only once instead of 3 times :) – in the solution itself I did mention the correct time complexity of O(n) as a comment.
True. Is there another way to mention the difference?
This is a O(n) solution, while all other solutions are O(3n). Thanks to Kevin, Ritu, David and Siemen for collaborating on this solution.
Thanks!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I think providing the map of what characters count as how many zeroes up-front would allow for a better experience.
Upvoting for best-practices because its one of the few solutions that loops only once over the input.
Upvoting for best-practices because its one of the few solutions that only loops once over the input.
This is indeed clever, but I wouldn't say best-practice: it loops over the ENTIRE input 3 times and then loops over the chunks individually.
I see your point, but on second thought I actually don't think its a good use-case: see my recent comment in the main thread..
This comment is hidden because it contains spoiler information about the solution
Array.chunk is definitely useful here for expressiveness, but doesn't it lead to an algorithm that loops over the input multiple times?
Most of the upvoted solutions do something like: chunk => map => map, which means 3 complete loops (or at best 2) over the input array.
So the tricky thing is making a one-liner that actually loops only ONCE over the input.