Matrix is symmetric
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 :
Input Format:
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.
Constraints:
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
CodingNinjas
author
2y
A Simple solution is to do the following.
1) Create transpose of given matrix.
2) Check if transpose and given matrices are same or not.
CodingNinjas
author
2y
Brute Force
- Create another matrix ‘TRANSPOSE’ of the same size initially having all zeros.
- Now replace ‘TRANSPOSE’ (i,j) with ‘MATRIX’ (j,i).
- And now traverse both matrixes element by element if anywhere...read more
CodingNinjas
author
2y
Optimised Approach
- Traverse the matrix element by element and compare ‘MATRIX' ( I, j) with 'MATRIX" ( j, i).
- And if anywhere there inequality exists between them simply return false from that point els...read more
Add answer anonymously...
Top Josh Technology Group Software Engineer interview questions & answers
Popular interview questions of Software Engineer
>
Josh Technology Group Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app