classSolution{ funsolution(rows: Int, columns: Int, queries: Array<IntArray>): IntArray { if (queries.size == 1) return intArrayOf(1) var answer = mutableListOf<Int>() val board = Array(rows) { i -> IntArray(columns) { j -> (i * columns) + j + 1 } }
queries.forEach { val list = LinkedList<Pair<Int, Int>>() val values = mutableListOf<Int>() val (row1, col1) = it[0] - 1 to it[1] - 1 val (row2, col2) = it[2] - 1 to it[3] - 1 var (tempRow, tempCol) = row1 to col1
while (tempCol < col2) { list.add(tempRow to tempCol) values.add(board[tempRow][tempCol]) tempCol += 1 }
while (tempRow < row2) { list.add(tempRow to tempCol) values.add(board[tempRow][tempCol]) tempRow += 1 }
while (tempCol > col1) { list.add(tempRow to tempCol) values.add(board[tempRow][tempCol]) tempCol -= 1 }
while (tempRow > row1) { list.add(tempRow to tempCol) values.add(board[tempRow][tempCol]) tempRow -= 1 }