Sequence Transformation
InterviewTime limit2sMemory limit128 MB
Repeatedly replace a sequence with its adjacent differences K times and print the resulting shorter sequence.
- Level
Easy2 of 10
- Topics
- Array, Simulation, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence A of length N. In one transformation, create a new sequence from the differences of adjacent elements. The new sequence B has length one less than the previous sequence, and B[i] = A[i+1] - A[i].
Given the initial sequence, output the sequence that remains after applying this transformation K times.
Input
The first line contains N and K. N is a positive integer not greater than 20, and K is an integer from 0 to N-1.
The second line contains N integers separated by commas (,). Each integer has absolute value at most 100.
Output
Print the sequence after K transformations on one line, with its values separated by commas (,).