1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/6kyu/the_supermarket_queue/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

25 lines
657 B
C#

using System;
public class Kata
{
public static int[] FilterOutZeroes(int[] queue) => Array.FindAll(queue, e => e > 0);
public static long QueueTime(int[] customers, int n)
{
var sum = 0l;
while (customers.Length > 0)
{
var upTo = Math.Min(n, customers.Length);
var shortest = customers[0];
for (var i = 1; i < upTo; i++)
if (customers[i] < shortest) shortest = customers[i];
sum += shortest;
for (var i = 0; i < upTo; i++) customers[i] -= shortest;
customers = FilterOutZeroes(customers);
}
return sum;
}
}