Shapeshifter

Report a typo

You already have a 2D-array inputArray. It is guaranteed that it has at least two nested arrays.

Create a new two-dimensional array with two nested arrays — the first and last arrays in inputArray — in reverse order. In other words, the last one should become the first, and vice versa.

Print the resulting array using the function contentDeepToString().

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

Sample Input 1:

val inputArray = arrayOf(
    arrayOf('P', 'R', 'O', 'G', 'R', 'A', 'M', 'M', 'I', 'N', 'G'),
    arrayOf('I', 'S'),
    arrayOf('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 inputArray = arrayOf(
        arrayOf(1, 2),
        arrayOf(3, 4),
        arrayOf(5, 6),
        arrayOf(7, 8)
)

Sample Output 2:

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

}
___

Create a free account to access the full topic