Is there any other best way to take 5 maximum numbers from 3 sorted arrays as in the code below:
Update:
Below code gives me the result, but I am not sure if this is only way
Input arrays may contain duplicates, but result must not
Efficient means we require less iterations while getting to the result.
I am looking for linq specific answer.
private void Take5MaxNumbers()
{
var a1 = new[] { 10, 25, 45, 65, 76 };
var a2 = new[] { 32, 43, 54, 62, 78, 85, 93, 102 };
var a3 = new[] { 54, 74, 98, 105 };
var finalArray = a1.Union(a2).Union(a3).OrderByDescending(x => x).Take(5);
foreach (var item in finalArray)
{
Console.Write(item + " ");
}
}
// Output:
105 102 98 93 85