Reverse elements

Report a typo

Imagine you have a collection and you need to add all the elements from that collection to another one. Write a function addElements(), which takes all the elements from your collection in reverse order, adds them to a list, and returns this list.

Sample Input 1:

8 11 24 65 7890 3565 234 43 67 343 6767 65 3565 1234

Sample Output 1:

[1234, 3565, 65, 6767, 343, 67, 43, 234, 3565, 7890, 65, 24, 11, 8]
[1234, 6767, 343, 67, 43, 234, 3565, 7890, 65, 24, 11, 8]
Write a program in Kotlin
fun main() {
val originalList = readln().split(" ").map { it }.toMutableList()
val originalSet = originalList.toMutableSet()

println(addElements(originalList))
println(addElements(originalSet))
}

// Write function addElements() here
___

Create a free account to access the full topic