I'm trying to pass a pre-written test with focus on performance. What is the most efficient way to return the sum of the two highest numbers in a List of int? I have tried the following and according to the test it wasn't fast enough when it comes to larger lists:
1. list.Sort();
list.Reverse();
return list[0] + list[1];
2. return list.OrderByDescending(num => num).FirstOrDefault() + list.OrderByDescending(num => num).Skip(1).FirstOrDefault();
3. var secondHighest = list.Distinct()
.OrderByDescending(i => i)
.Skip(1)
.First();
return list.Max() + secondHighest;