Shapeshifter

Report a typo

Imagine you have a 2D list inputList. It is guaranteed that it has at least two nested lists.

Create a new two-dimensional list with two nested lists — the first and last lists from inputList — in reverse order. In other words, the last one should become the first, and vice versa.

Print the resulting list.

Tip: You can use first() and last().

Sample Input 1:

val inputList = mutableListOf(
    mutableListOf('P', 'R', 'O', 'G', 'R', 'A', 'M', 'M', 'I', 'N', 'G'),
    mutableListOf('I', 'S'),
    mutableListOf('M', 'A', 'G', 'I', 'C')
)

Sample Output 1:

[[M, A, G, I, C], [P, R, O, G, R, A, M, M, I, N, G]]

Sample Input 2:

val inputList = mutableListOf(
        mutableListOf(1, 2),
        mutableListOf(3, 4),
        mutableListOf(5, 6),
        mutableListOf(7, 8)
)

Sample Output 2:

[[7, 8], [1, 2]]
Write a program in Kotlin
fun main() {
// Do not touch code below
val inputList: MutableList<MutableList<String>> = mutableListOf()
val n = readLine()!!.toInt()
for (i in 0 until n) {
val strings = readLine()!!.split(' ').toMutableList()
inputList.add(strings)
}
// write your code here

}
___

Create a free account to access the full topic