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.
Many times it does. By just reading your comment, one gets a serious hint about how to solve this kata.
Ah, so any code fragment in the comments merits spoiler flag?
Please use a spoiler flag, comments are visible to everyone by default. I've just put the flag on for you this time.
This comment is hidden because it contains spoiler information about the solution
Nicely done, had a similar idea, but yours is better structured.
Nice work. My first inclination was to use a dictionary as well but threw together what I felt was an elegant solution not realizing that I had pushed myself past linear time. My solution was O(n^2).
vs this I found that with arrays with significant data, your solution out performed my solution significantly. It's less evident on smaller arrays so I'm thankful I dug a bit further to illustrate this for myself. +1'd
I definitely hadn't appreciated the virtues of dictionaries, until now!
Thanks for the great insight
This comment is hidden because it contains spoiler information about the solution
This is essentially the same as my solution and I believe it to be best practice, although I am not that experienced. I have noticed that the highest vote earning solutions always tend to be those that cram all the code into a single line, regardless and even when it is less efficient and less readable.
This comment is hidden because it contains spoiler information about the solution
Can someone explain this solution please?
Best answer!
Clean code and the most efficient. O(N) and only one pass
This comment is hidden because it contains spoiler information about the solution
I also used a dict based solution, which I think is the way to go here, but I didnt consider using a default value, very nice.