Sums of Parts in Kotlin
The challenge
Let us consider this example (array written in general format):
ls = [0, 1, 3, 6, 10]
Its following parts:
The corresponding sums are (put together in a list): [20, 20, 19, 16, 10, 0]
The function parts_sums
(or its variants in other languages) will take as parameter a list ls
and return a list of the sums of its parts as defined above.
Other Examples:
The solution in Kotlin
Option 1:
Option 2:
Option 3:
Test cases to validate our solution
|
|