Ad
  • Custom User Avatar

    The expected complexity should be O(str1.length + str2.length). Your solution is O(N^2) because searching is O(N)

  • Custom User Avatar

    Not a kata suggestion.

  • Default User Avatar

    Thanks for the info, will try to improve my coding.

  • Default User Avatar

    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 line if x in list is also a loop - when this line is reached, your code is actually going to loop through every element in list until it finds x.

    This is why your approach is timing out, it has complexity O(n^2) even though this is "hidden" by the above fact.

  • Default User Avatar

    Am I not supposed to use loops since performance is checked as ok but the execution still times out?

  • Custom User Avatar

    Fixed by someone.

  • Custom User Avatar

    Problems with performance of tests were cased by a fu broken implementation of shuffle, should be fixed now.

  • Custom User Avatar

    Fixed.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution