Ad
  • Default User Avatar

    It loops for the entire length of an array even if a solution is found at early index.

  • Default User Avatar

    plus I think most of us know the voting system is broken. they should do away with clever and best practices. maybe replace it with 'favourite solution' instead.

  • Default User Avatar

    I don't see it as a big deal. I'm not disagreeing with you that it's inefficient. I think people obsess a little bit too much about time complexity on codewars. It's not like we're doing this as our day job. Most of the time we write code and if it works and passes the tests, then great, either refactor or move on to the next one. I wrote my solution and didn't care enough to refactor because it isn't time critical code. Python's great for fast prototyping.

  • Custom User Avatar

    but how chopping the string step by step could be anything else than bad when you can do that in one single step??

  • Default User Avatar

    reverse engineer as in to see how it works? I'd either inject some print statements along the way to see what happens with each iteration, or just get experienced with the language to know what to expect. Once you've been coding in a language for awhile you'll get to the point of knowing what will throw errors and what they'll be, and ultimately how things just work.

  • Default User Avatar

    this kata isn't designed to be time sensitive though. Honestly, if you're passing the tests within time, I wouldn't really call any solution 'bad'. Inefficient would be technically correct. either way, this solution is readable and gets the job done.

  • Custom User Avatar

    do people realize that this solution is O(n²)...? Hence it's not a good solution.

  • Custom User Avatar

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

  • Custom User Avatar

    Can someone please explain this?

  • Custom User Avatar

    Is it more efficient to use a loop or to use reduce()? How do I learn how to write code that will be marked as clever or best practice? Thanks.

  • Custom User Avatar

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