# PROBLEM LINK:

**Author:** Siddhartha Paul

**Editorialist:** Baban Gain

# DIFFICULTY:

EASY

# PREREQUISITES:

None

# PROBLEM:

A 8*8 matrix will be given. Rotate all elements of a selected row or column as specified by input.

# EXPLANATION:

Let N = 8

If no. of shifts is greater than N,

then no, of shift N+1, 2N+1, 3N+1… are equivalent to 1 shift

similarly N+2, 2N+, 3N+2… are equivalent to 2 shift and so on.

Initialise an temporary array of size N.

So, if it is a Row operation,

for every element in that row R,

temp[(i + shift) % N] = arr[R][i]

and copy back the temporary array to original matrix’s Rth row.

And it is a Column operation,

for every element in that col C,

temp[(i + shift) % N] = arr[i][C];

and copy back the temporary array to original matrix’s Cth column.