Skip to content

Commit 4a0f6aa

Browse files
authored
Create 2028-find-missing-observations.kt
1 parent 2018e17 commit 4a0f6aa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
fun missingRolls(rolls: IntArray, mean: Int, _n: Int): IntArray {
3+
val m = rolls.size
4+
var n = _n
5+
var nTotal = (mean * (n + m)) - (rolls.sum() ?: 0)
6+
7+
if (nTotal < n || nTotal > n * 6)
8+
return IntArray (0)
9+
10+
var res = LinkedList<Int>()
11+
while (nTotal > 0) {
12+
val dice = minOf(nTotal - n + 1, 6)
13+
res.add(dice)
14+
nTotal -= dice
15+
n--
16+
}
17+
18+
return res.toIntArray()
19+
}
20+
}

0 commit comments

Comments
 (0)