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 expected complexity should be O(str1.length + str2.length). Your solution is O(N^2) because searching is O(N)
Not a kata suggestion.
Thanks for the info, will try to improve my coding.
Hi, and welcome to Codewars!
You can "use loops" - but you have to make sure you understand what exactly your algorithm is doing to understand its actual complexity.
It is a common mistake to only think of stuff like
for x in list..
as being "a loop" (because you can actually see the word "for" in it), but in fact in your code the lineif x in list
is also a loop - when this line is reached, your code is actually going to loop through every element inlist
until it findsx
.This is why your approach is timing out, it has complexity O(n^2) even though this is "hidden" by the above fact.
Am I not supposed to use loops since performance is checked as ok but the execution still times out?
Fixed by someone.
Problems with performance of tests were cased by a
fubroken implementation ofshuffle
, should be fixed now.Fixed.
This comment is hidden because it contains spoiler information about the solution
With your code in repl.it I get the wrong result. The test string is this:
71899703 200 6 91 425 4 67407 7 96488 6 4 2 7 31064 9 7920 1 34608557 27 72 18 81
. You need to fix your sort function.This comment is hidden because it contains spoiler information about the solution