Skip to content

Commit 91581fb

Browse files
authored
Create Find Missing Observations.java
1 parent 2b51bee commit 91581fb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Medium/Find Missing Observations.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int[] missingRolls(int[] rolls, int mean, int n) {
3+
int currSum = Arrays.stream(rolls).sum();
4+
int missingSum = mean * (n + rolls.length) - currSum;
5+
if (missingSum > n * 6 || missingSum < n) {
6+
return new int[]{};
7+
}
8+
int[] ans = new int[n];
9+
int part = missingSum / n;
10+
int remainder = missingSum % n;
11+
Arrays.fill(ans, part);
12+
for (int i = 0; i < remainder; i++) {
13+
ans[i]++;
14+
}
15+
return ans;
16+
}
17+
}

0 commit comments

Comments
 (0)