1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-18 21:56:57 +02:00
CodeWars/6kyu/the_supermarket_queue/solution.cs

26 lines
657 B
C#
Raw Normal View History

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;
}
}