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
Stevele like your solution man, keep it up.
markus.benko, that is a crazy smart solution you have. Here I was feeling happy about my use of a hashmap.
I also don't know why but it seems to happen quite often that solutions are considered best practice which clearly shows that the idea of Green Computing hasn't reached most software developers. Too bad that we can't downvote, beginners really shouldn't learn from solutions like this one. And believe it or not, my solution is about 100 times as fast as this one for both strings = "abc...xyz" and it doesn't even create intermediate objects or arrays most of the time. ;-) What I have to admit is that I have forgotten to shortcut cases where
str2
is longer thanstr1
.Agree. Relative performance can be measured objectively, so I think it should be measured by codewars itself for each propossed solution and shown there.
Agreed. This solution is indeed clean and nicely organized. However if performance is to be considered, this solution is not as good as others are.
Why is an O(n^2) solution voted to Best Practices (and Clever?!) for a Kata with "Performance" and "Optimization" tags? The description even says
My solution (and others that haven't been voted to the top) are O(n) and arguably more clever than this brute-force method.
This program runs in O(N*M) since
str1.contains(s) is O(N) with N = length(str1), M = length(str2)
Using List it takes O(N) only, N = max length of (str1, str2).
This comment is hidden because it contains spoiler information about the solution