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.
how is mine?
This comment is hidden because it contains spoiler information about the solution
It's not the most optimal though. With larger inputs, the difference will start to become noticeable. You should totally avoid iterating twice.
How did I not think of that?! It's so easy!
i basically did the same but long way but i think is not the best with O(2n) why is this top in the first place becuase is short or what ?
Do you need to handle errors? Like if the array has no outliers or more than 1? Or the array is smaller than 3?
going over the "very large array" twice ends up taking twice as long, twice as much memory.
if the array was billions of members long - the 10 lines of code you saved would cost a lost of money.
this code may be impressive to newbies exclusively.
definitely not best practice, you use var, not strict equality operator and filter array twice
This solution is at least 8 years old.
stop using var please, is missleading
Thanks, I just started reading Groking algorithms to be more competent
There is no such thing as 'O(2n)' in big O notation. There are different notations which keeps the constant multiplier before function, such as 'tilde notation', see https://www.reddit.com/r/compsci/comments/1bl0q8/tilde_notation/. But you are right this solution is quite inefficient.
Lol, author says that array can be VERY big, and O(2n) solution gots top place when O(1) solution takes hardly more time to come with)
I'm not saying mine is better, jsut asking a question mate, i'm here to learn.
Loading more items...