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.
It loops for the entire length of an array even if a solution is found at early index.
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.
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.
but how chopping the string step by step could be anything else than bad when you can do that in one single step??
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.
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.
do people realize that this solution is O(n²)...? Hence it's not a good solution.
This comment is hidden because it contains spoiler information about the solution
Can someone please explain this?
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.
This comment is hidden because it contains spoiler information about the solution