From add853b5e4b52630fbe66472ede5a981be1ee63d Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 5 Sep 2024 10:52:04 +0200 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB2028.=20Find=20Missing=20Obse?= =?UTF-8?q?rvations=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- cs/find-missing-observations.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cs/find-missing-observations.cs diff --git a/cs/find-missing-observations.cs b/cs/find-missing-observations.cs new file mode 100644 index 0000000..a154874 --- /dev/null +++ b/cs/find-missing-observations.cs @@ -0,0 +1,22 @@ +public class Solution { + public int[] MissingRolls(int[] rolls, int mean, int n) { + var sum = rolls.Sum(); + + var remainder = (rolls.Length + n) * mean - sum; + if (remainder < n || remainder > 6 * n) { + // cannot construct such rolls + return []; + } + + var (roll, unmatched) = (remainder / n, remainder % n); + + var missing = new int[n]; + Array.Fill(missing, roll); + + for (int i = 0; i < unmatched; ++i) { + ++missing[i]; + } + + return missing; + } +}