Loading Now

symmetricalMatrix

Given a square matrix of integers, your task is to determine whether or not it’s symmetric along its main diagonal.

Example

  • For 
    matrix = [[0,1,2],
              [1,5,3],
              [2,3,4]], 
    the output should be symmetricalMatrix(n, matrix) = true.

    This matrix is symmetric along the main diagonal!

  • For 
    matrix = [[0,0,0],
              [0,0,0],
              [1,0,0]], 
    the output should be symmetricalMatrix(n, matrix) = false.

    This matrix is not symmetric (the and 1 don’t match up).

Input / Output

  • [execution time limit] 1 seconds 

  • [input] integer n

    An integer representing the number of rows and columns in the matrix.

    Guaranteed constraints:
    1 ≤ n ≤ 100

  • [input] an array of integers

    A square matrix of integers.

    Guaranteed constraints:
    matrix.length = n
    matrix[i].length = n
    0 ≤ matrix[i][j] ≤ 104

  • [output] boolean

    • Return true if matrix is symmetric along the main diagonal, and false otherwise.

Post Comment

Contact