using System.Diagnostics;
using System.Collections.Generic;
public static Dictionary<string, double>[] DoAggregations(double[,] input)
var solutiondictionary_obj = new Dictionary<string, double>[input.GetLength(0)];
for(int a = 0; a < input.GetLength(1); a++){
var array_list = new List<double>();
for (int b = 0; b < input.GetLength(0); b++){
array_list.Add(input[b, a]);
solutiondictionary_obj.SetValue(new Dictionary<string, double>() { {"SUM", array_list.Sum()}, {"AVERAGE", array_list.Sum()/array_list.Count()}, {"COUNT DISTINCT", array_list.Distinct().Count()}}, a);
return solutiondictionary_obj;
public static Dictionary<string, double>[] DoAggregations(double[,] input)
return new Dictionary<string, double>[]{
new Dictionary<string, double>{{"SUM", 9d}, {"AVERAGE", 2.25d}, {"COUNT DISTINCT", 3d}},
new Dictionary<string, double>{{"SUM", 14d}, {"AVERAGE", 3.5d}, {"COUNT DISTINCT", 2d}},
new Dictionary<string, double>{{"SUM", 16d}, {"AVERAGE", 4d}, {"COUNT DISTINCT", 4d}}};
public static void Main()
double[,] smallInput = new double[,] { { 1, 4, 3 }, { 2, 3, 4 }, { 1, 3, 7 }, { 5, 4, 2 } };
Console.WriteLine("=== Small Input - Mocked Execution ===");
var mockResult = Mock.DoAggregations(smallInput);
IsResultCorrect(mockResult);
Console.WriteLine("\n=== Small Input - Solution Execution ===");
var result = Solution.DoAggregations(smallInput);
Console.WriteLine("\n=== Large Input - Solution Execution ===");
var largeInput = GenerateLargeInput();
var sw = Stopwatch.StartNew();
Solution.DoAggregations(largeInput);
IsExecutionFastEnough(sw.ElapsedMilliseconds/5);
public static double[,] GenerateLargeInput()
var input = new double[numRows, numCols];
Random rnd = new Random(123);
for (int col = 0; col < numCols; col++)
for (int row = 0; row < numRows; row++)
input[row, col] = rnd.Next(100000);
public static void IsResultCorrect(Dictionary<string, double>[] result)
result[0]["SUM"] == 9d &&
result[1]["SUM"] == 14d &&
result[2]["SUM"] == 16d &&
result[0]["AVERAGE"] == 2.25d &&
result[1]["AVERAGE"] == 3.5d &&
result[2]["AVERAGE"] == 4d &&
result[0]["COUNT DISTINCT"] == 3d &&
result[1]["COUNT DISTINCT"] == 2d &&
result[2]["COUNT DISTINCT"] == 4d
Console.WriteLine("IsResultCorrect Passed");
Console.WriteLine("IsResultCorrect Failed");
public static void IsExecutionFastEnough(double milliSeconds)
Console.WriteLine($"IsExecutionFastEnough DIAMOND!!!: {milliSeconds}ms");
else if(milliSeconds < 105)
Console.WriteLine($"IsExecutionFastEnough GOLD!: {milliSeconds}ms");
else if(milliSeconds < 150)
Console.WriteLine($"IsExecutionFastEnough SILVER: {milliSeconds}ms");
Console.WriteLine($"IsExecutionFastEnough BRONZE: {milliSeconds}ms");