Corners

Report a typo

Imagine you have a 2D list inputList,whose dimension is greater than or equal to two. Print all of its corner elements in the following order: left to right and top to bottom.

Print the result for two elements in one line. Use a single space to separate two elements on the same line.

Take a look at the examples below and remember that nested lists can be of different lengths!

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

Sample Input 1:

3
1 0 1
0 0 0
1 0 1

Sample Output 1:

1 1
1 1

Sample Input 2:

2
2 2
2 2

Sample Output 2:

2 2
2 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