1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-08 18:49:07 +01:00
CodeWars/6kyu/length_of_missing_array/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

21 lines
653 B
C#

using System.Collections.Generic;
using System.Linq;
public class Kata {
public static int GetLengthOfMissingArray(object[][] arrayOfArrays) {
if (arrayOfArrays == null || arrayOfArrays.GetLength(0) < 2) return 0;
var lengths = new HashSet<int>();
foreach (var array in arrayOfArrays) {
if (array == null) return 0;
var size = array.GetLength(0);
if (size == 0) return 0;
else lengths.Add(size);
}
var max = lengths.Max();
var min = lengths.Min();
return (int) (0.5 * (arrayOfArrays.GetLength(0) + 1) * (max + min) - lengths.Sum());
}
}