Partial Sums
Practice this coding question on Coding Gurukul.
Problem statement
A reporting pipeline repeatedly turns daily readings into cumulative readings. During each pass, every position becomes the sum of all positions up to it in the previous array. The pipeline may run billions of passes, so the analyst needs the final array without simulating each pass individually. Your task Apply k prefix-sum transformations to a. In one transformation, new[i] is the sum of old[1] through old[i], reduced modulo 1000000007. Output the array after exactly k transformations. Important details Every position in a pass is defined from the array at the start of that pass. For k = 0, print the input unchanged. Reduce arithmetic modulo 1000000007 to keep values bounded. The large k bound rules out repeating an O(n) pass k times. Worked example For a = 2 1 3 and k = 2, the first pass gives 2 3 6 and the second gives 2 5 11. Print 2 5 11. With a single element, every pass leaves that element unchanged, even when k is very large.
Input format
Read n k, then n nonnegative integers.
Output format
Print the n final values separated by spaces.
Constraints
1 <= n <= 1000; 0 <= k <= 1000000000; 0 <= a[i] <= 1000000000.
Sample input
3 2 2 1 3
Sample output
2 5 11
Sign in to run or submit a solution in C++, Java or Python.