kotlin-coding-challenges

Max sub-list sum

Instructions

Given list of integers and integer n implement a function which calculates the maximum sum of n consecutive elements in the list (sum of n digits next to another that have the largest sum).

You can use helper max function to deal with Kotlin nullability.

Challenge Solution

Examples

maxSubListSum(listOf<Int>(), 3) // null

maxSubListSum(listOf(4, 2, 7), 2) // 9

maxSubListSum(listOf(4, 2, 7, 5, 8, 9, 5, 1), 3) // 22

Hints

Hint 1 Use sliding window