Problem of the day
You are given a square matrix, return true if the matrix is symmetric otherwise return false.
A symmetric matrix is that matrix whose transpose is equal to the matrix itself.
Example of symmetric matrix :
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains the size of the square matrix 'N'.
The second line of each test case contains the 'N' * 'N' Integers separated by a single space (the matrix is entered row-wise)
Output format :
For each test case/query, print whether the given matrix is symmetric or not.
Output for every test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^2
-10^9 <= data <= 10^9
Where 'data' denotes the element in the given 'matrix'.
Time Limit: 1 sec
1
3
1 2 3 2 4 5 3 5 8
Yes
1
3
1 2 3 1 4 5 3 5 8
No
Try to create the transpose of the matrix.
O(N^2) , Where ‘N’ is the size of the square matrix.
Since every element is visited once and there are ‘N’ ^2 elements in total. Hence the overall time complexity is O(N^2).
O(N ^ 2), Where ‘N’ is the size of the square matrix.
Since an extra matrix of size ‘N’ * ‘N’ is created while making transpose of the matrix. Hence overall space complexity is O(N * N).