2028. Find Missing Observations Medium
1/**
2 * [2028] Find Missing Observations
3 *
4 * You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.
5 * You are given an integer array rolls of length m where rolls[i] is the value of the i^th observation. You are also given the two integers mean and n.
6 * Return an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.
7 * The average value of a set of k numbers is the sum of the numbers divided by k.
8 * Note that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.
9 *
10 * Example 1:
11 *
12 * Input: rolls = [3,2,4,3], mean = 4, n = 2
13 * Output: [6,6]
14 * Explanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.
15 *
16 * Example 2:
17 *
18 * Input: rolls = [1,5,6], mean = 3, n = 4
19 * Output: [2,3,2,2]
20 * Explanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.
21 *
22 * Example 3:
23 *
24 * Input: rolls = [1,2,3,4], mean = 6, n = 4
25 * Output: []
26 * Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
27 *
28 *
29 * Constraints:
30 *
31 * m == rolls.length
32 * 1 <= n, m <= 10^5
33 * 1 <= rolls[i], mean <= 6
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/find-missing-observations/
39// discuss: https://leetcode.com/problems/find-missing-observations/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn missing_rolls(rolls: Vec<i32>, mean: i32, n: i32) -> Vec<i32> {
45 vec![]
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2028() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.