Kotlinlearncs.online LogoJava
Return to List

Solve: Array Pairwise Sum

Created By: Pranav Narayanan
/ Version: 2025.2.0

Write a method arrayPairwiseSum that takes an IntArray and returns an array with the pairwise sums of all the elements.

For example, given the array {1, 2} you would return the array {3}. Given the array {1, 3, 5} you would return the array {4, 8}. (1 + 3 = 4; 3 + 5 = 8).

Note that the input array must have at least 2 elements to be valid. If the passed array has less than 2 elements, throw an IllegalArgumentException.

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/kotlin/array-pairwise-sum/[email protected]