https://leetcode.com/problems/shift-2d-grid/description/ Easy

Решение

class Solution {
    fun shiftGrid(grid: Array<IntArray>, k: Int): List<List<Int>> {
        val m = grid.size
        val n = grid[0].size
        val total = m * n
        val result = Array(m) { IntArray(n) }
        for (i in 0 until m) {
            for (j in 0 until n) {
                val index = (i * n + j + k) % total
                result[index / n][index % n] = grid[i][j]
            }
        }
        return result.map { it.toList() }
    }
}