REVENG02 - Editorial

PROBLEM LINK:

Practice

Contest

Author: Akshat Jain

Tester: Ankit Kathuria

Editorialist: Akshat Jain

DIFFICULTY:

EASY-MEDIUM

PREREQUISITES:

Interest in Coding, Arrays, Matrices.

PROBLEM:

Finding the problem is the first task based on the input, output format and exe file provided. Then think the logic and code the same.

QUICK EXPLANATION:

The task in this problem is to rotate the matrix layer by layer anticlockwise.

EXPLANATION:

• The first input is the number of test cases.

• Among the next three input the first two (say m and n) are order of matrix, and the third (say r) is the number of times rotation is to be done at each layer in an anticlockwise manner.

• All input next are the content of the matrix.

• The smaller of the two m or n, say m(necessarily even due to constraints) is to be divided by 2 to calculate number of layers(m/2), and each of these layers can be stored into different lists(array).

Matrix:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

Lists:

1 2 3 4 8 12 16 15 14 13 9 5

6 7 11 10

• Now, each of these lists can be rotated in anticlockwise manner accordingly by just moving the first element towards end of the list r (m=4,n=4,r=1 in example) times.

Matrix:

2 3 4 8

1 7 11 12

5 6 10 16

9 13 14 15

Lists:

2 3 4 8 12 16 15 14 13 9 5 1

7 11 10 6

• Finally the lists must be displayed in the form of matrix.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.

Tester’s solution can be found here.

//