Shift 2D Grid Problem

Shift 2D Grid Problem — ExecCode Easy DSA Practice

Solve the Shift 2D Grid problem on ExecCode. Free online easy DSA practice in Matrix. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 2D grid of size m x n and an integer k. Your task is to compute the required answer and return the 2D grid after applying shift operation k times. You need to shift the grid k times. In one shift operation: - Element at grid[i][j] moves to grid[i][j + 1]. - Element at grid[i][n - 1] moves to grid[i + 1][0].

Examples

Input {"grid": [[1, 2, 3], [4, 5, 6], [7, 8, 9]], "k": 1}; Output 9 1 2 3 4 5 6 7 8. Input {"grid": [[1, 2, 3], [4, 5, 6], [7, 8, 9]], "k": 9}; Output 1 2 3 4 5 6 7 8 9. Input {"grid": [[5]], "k": 1}; Output 5

Constraints

m == grid.length n == grid[i].length 1 <= m <= 50 1 <= n <= 50 -1000 <= grid[i][j] <= 1000 0 <= k <= 100

Practice Shift 2D Grid free on ExecCode. Browse DSA problems, topic map, and placement guides.