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.
This comment is hidden because it contains spoiler information about the solution
I'm not too sure, but I think these builtins are internally written in C, making them automatically blazing fast. Calling the solution "horribly inefficient" is really dramatic. On the grand scheme of things, this is still an O(n) solution. It is also incredibly readable. I have run some cursory benchmarks and the "inefficient" method gobsmacks yours for all list lengths I've tried (we're talking around more than 3x faster than yours). Take this with a grain of salt since they're informal tests, but it should hopefully make you reconsider making hasty performance comments in the future. I'll attach it spoilered below.
Moreover builtin functions are optimized in Python, and I would not be surprised if this solution were actually faster than a single loop over the list.
That's why be in hurry for efficiency is too far from the target in this problem.
In this case, I prefer a more readable solution... that's ok all the matter about the performance but, also the context is very important.
No. If you parse the array twice it's still O(N) (O(2N) == O(N)). O(N^2) would be the case of a nested loop.
if you want efficiency, you should use other programming languages...
Python is not famous for its efficiency...
you absolutely should do this in an interview, it shows understanding of the language methods. But come on, nobody is going to ask this in an interview anyway.
why?it's good
unless its coding in python...? please state why. This is more understandable for other, especially more lower-level / typed languages... but why?