Matrix Permutation

Given a matrix of integers A of size N x N.Find whether all rows are circular rotations of each other or not.

Return “YES”,if all rows of A are circular rotations of each other, else return “NO”.

Note: Rows are numbered from top to bottom and columns are numbered from left to right.



Input Format

The first argument given is the integer matrix A.

Output Format

Return "YES",if all rows of A are circular rotations of each other, else return "NO".

Constraints

1 <= N <= 1000
1 <= A[i] <= 100000

For Example

Input 1:
    A = [   [1, 2, 3]
            [3, 2, 1]
            [2, 3, 1]   ]
Output 1:
    NO

Input 2:
    A = [   [1, 2, 2, 1]
            [1, 1, 2, 2]
            [2, 1, 1, 2]    
            [1, 1, 2, 2]    ]
Output 2:
    YES
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Matrix Permutation on Interview Code Editor
Sign Up
to access hints and editorial solutions for Matrix Permutation

Discussion


Loading...
Click here to start solving coding interview questions