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.
Your solution is O(n^2), because you have a for-in and an if-in statement with a list comprehension!
Because there are tests that involve 10 million elements, even if you had a computer that could iterate through 1 million elements a second, it would take over 13 thousand hours for the entire array to be parsed if there are no matches.
(10000000*(10000000-1)/2)/(1000000*3600) = 13888.8875
(3600 is the number of seconds in an hour)
good to see Blind4Basics giving his/her normal 'because its more efficient' reply when it clearly isn't.
Yeah, I agree. I started going this way and realized it was probably complicated enough to justify more verbosity. I wouldn't say this is best practice. Certainly clever though.
I solved it the same way at first, but in no way is this more efficient.
At least take the n*2-1 calculation out of the list comprehension. you don't need to calculate that in every loop.
Check my solutions.
because it's more efficient than a deployed loop