Minimum Amount of Time to Fill Cups LeetCode solution in JavaScript

1
var fillCups = function (amount) {
2
var count = 0;
3
var a = amount;
4
while (eval(a.join("+")) > 0) {
5
var max = Math.max(...a);
6
a.splice(a.indexOf(max), 1);
7
var max2 = Math.max(...a);
8
a.splice(a.indexOf(max2), 1);
9
count++;
10
if (max == 0) a.push(0);
11
else a.push(max - 1);
12
if (max2 == 0) a.push(0);
13
else a.push(max2 - 1);
14
}
15
return count;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0