Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have just rolled a dice several times. The N roll results that you remember are described by an array A . However, there are

You have just rolled a dice several times. The N roll results that you remember are described by an array A. However, there are F rolls whose results you have forgotten. The arithmetic mean of all of the roll results (the sum
of all the roll results divided by the number of rolls) equals M .
What are the possible results of the missing rolls?
Write a function:
function solution(A, F, M);
that, given an array A of length N , an integer F and an integer M , returns an array containing possible results of the missed rolls. The returned array should contain F integers from 1 to 6(valid dice rolls). If such an array does
not exist then the function should return 0.
Examples:
Given A=[3,2,4,3],F=2,M=4, your function should return 6,6. The arithmetic mean of all the rolls is 3+2+4+3+6+66=246=4.
Given A=[1,5,6],F=4,M=3, your function may return 2,1,2,4 or 6,1,1,1(among others).
Given A=[1,2,3,4],F=4,M=6, your function should return [0]. It is not possible to obtain such a mean.
Given A=[6,1],F=1,M=1, your function should return [0]. It is not possible to obtain such a mean.
Write an efficient algorithm for the following assumptions:
N and F are integers within the range 1..100,000;
each element of array A is an integer within the range [1..6];
M is an integer within the range [1..6].
Remember, all submissions are being checked for plagiarism. Your recruiter will be informed in case suspicious activity is detected. Please solve this in typescript. Thank you
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions