@Pankwood, @thanhdoan
Problem here is not a O()
Problem here is an IEnumerable in C#.
Possible, it can be infinite.
You can try it with simple method: https://gist.github.com/IDontKnower/5df0a1a5d957ec37f719674eafeeacf4
I think, in my example it's realy hard to get GroupBy or Sort)
Most solutions here parse through the entire collection and are far from optimal. What if the collection contained a file with 10 trillion numbers and the offending number was 4th on the list or worse 1st on the list. Why parse a collection that big only to discover the offending number was 1st on the list ?
That feeling when you created a dictionary, and then two more cycle, and the guys did everything in one line =)
О(n)+O(1-2)?
it really should have a failing test on memory allocation with some IEnumberable the generates billions of values.
@Pankwood, @thanhdoan
Problem here is not a O()
Problem here is an IEnumerable in C#.
Possible, it can be infinite.
You can try it with simple method: https://gist.github.com/IDontKnower/5df0a1a5d957ec37f719674eafeeacf4
I think, in my example it's realy hard to get GroupBy or Sort)
More code BUT definitely more optimal than 99% of the solutions here. Optimal is the way !!
Nice simple 1 liner BUT certainly not optimal.
Most solutions here parse through the entire collection and are far from optimal. What if the collection contained a file with 10 trillion numbers and the offending number was 4th on the list or worse 1st on the list. Why parse a collection that big only to discover the offending number was 1st on the list ?
Rather a few more lines of code.