Fork me on GitHub
#100-days-of-code
<
2019-07-01
Abhishek10:07:07

Sam is fond of chocolates, so Alex gave Sam some boxes of chocolates as a gift. Sam wants to choose one or more boxes of chocolates such that the average number of chocolates in the chosen boxes is exactly equal to some integer k. Given the number of chocolates in each box, determine the number of ways Sam can choose boxes such that the average number of chocolates across the chosen boxes is equal to k. Since the result may be very large, return the value modulo (109+7). For example, Alex bought 3 boxes of chocolates containing chocolate = [3, 2, 4] chocolates in the boxes. Sam wants to choose boxes such that the average number of chocolates among the chosen boxes is k = 3. The boxes can be selected in the following 3 ways: Take chocolate[0] having 3 chocolates. Take chocolate[0, 1, 2] having (3, 2, 4) chocolates respectively, (3+2+4)/3 = 3 Take chocolate[1, 2] having (2, 4) chocolates respectively, (2+4)/2 = 3 Return the answer 3%(109+7) = 3. Function Description Complete the function chocolateBoxes in the editor below. The function should return an integer, the number of ways to choose boxes, modulo (109+7). chocolateBoxes has the following parameter(s): k : an integer denoting the average number of chocolates chocolate[chocolate[0], chocolate[1] .... chocolate[n-1]]: an integer array where chocolate[i] denotes the number of chocolates in ith box. Constraints 1≤ k ≤ 50 1≤ n ≤ 50 1 ≤ chocolate[i] ≤ 50 Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing 3 6 3 2 4 5 1 12 Sample Output 7

Abhishek10:07:24

this is question asked in infosys power programmer contest can anyone help me with the code of above