Question bank › Matrix
Dsa Matrix Medium

Matrix Row Shifter

Given a 2D matrix of integers, implement a program that rotates each row to the right by a specified number of positions. Positions that fall off the end wrap around to the beginning. Input Format: - The first line contains two integers, m and n, representing the number of rows and columns. - The next m lines each contain n space-separated integers representing the matrix rows. - The last line contains an integer k, the number of positions to rotate each row. Output Format: - The rotated matrix should be printed, with each row on a new line. Example: Input: 3 4 1 2 3 4 5 6 7 8 9 10 11 12 2 Output: 3 4 1 2 7 8 5 6 11 12 9 10

Key concepts

matrixshiftarray manipulation

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.