Menu
Coddy logo textTech

Recap - Reversed List

Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 73 of 93.

challenge icon

Challenge

Medium

Write a function reverseAndSum that takes a list of integers, reverses it, and returns the sum of the first three elements of the reversed list.

If the reversed list has fewer than three elements, return the sum of all available elements.

Parameters:

  • numbers (List<Int>): A list of integers

Returns: The sum of the first three elements from the reversed list (or all elements if fewer than three exist).

Try it yourself

fun reverseAndSum(numbers: List<Int>): Int {
    // Write code here
}

All lessons in Fundamentals

Practice on your own: Kotlin playground