Upside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number.
When given the numbers 2, 1, 1
the following process occurs:
2 1 1
3 2
5
This ends in the number 5
.
YOUR TASK
Given the right side of an Upside-Down Pyramid (Ascending), write a program or function that will return the original list.
New Extra Challenge: Try doing this in less than O(n^2)
EXAMPLE
f([5, 2, 1]) => [2, 1, 1]
f([84,42,21,10,2]) => [4,7,3,8,2]
NOTE: The Upside-Down Pyramid will never be empty and will always consist of positive integers ONLY.
Try doing this in less than O(n)
surely it's impossible to allocate a n-sized array or change O(n) items in it faster than O(n) complexity? \$\endgroup\$