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.
As was mentioned above, try using some datastructure that has something like a hash table for lookups of possible solutions. Something like a dictionary in Python, an associative array in PHP, a map in Elixir, etc.
This comment is hidden because it contains spoiler information about the solution
Many people have already solved the kata in Python so the kata works. If your code is not efficient enough or it doesn't work, why not blame yourself instead of the kata?
Going on to downvote all my comments does not prove that you're right, or I'm wrong.
The point here is that, what "you think" doesn't matter, the kata works (as the stats have shown) and you're not doing anything by just disagreeing and claiming it doesn't work. Or: you need to
git gud
.Emm, I use an "in" inside a single loop so it should be O(n**2) right?
Then I need to find a real O(n) to solve the problem...?
I don't think that resolves this issue.
Search rather on the side of a useful data container to store/retrieve useful informations. ;)
Thanks for pointing me in the right direction. This time I spent time diagraming the process by taking possible combinations in a more efficient way. At least I managed to decrease the total lines of code from 12 to 5! It's a start... but still can't solve problem using O(n). Need to sleep on it for tonight.
Thanks again!
Is there any cool or special built-in functions that I might be missing? I just learned about enumerate a few hours ago... I realize I don't need it for this problem. (My first stab at the problem uses the enumerate() function, while I didn't use it this time around).
2 loops, that's O(n^2). You need a O(n) solution, with a single loop.
I ran my code and it works for the sample test case, but still having optimization issues... I guess my code is too inefficient? Can someone help point me to the right direction?
I'm using a for loop and another for loop nested inside to do a compare... (obviously that's not a "clever" solution as I'm still learning the syntax and idioms for a cleaner approach)...