Validate a Latin Square
Problem statement
You are given an n by n integer matrix. A Latin square contains every integer from 1 through n exactly once in each row and exactly once in each column.
Return true if the matrix is a Latin square, otherwise return false. Diagonals have no additional requirement.
Function
isLatinSquare(matrix: int[][]) → booleanExamples
Example 1
matrix = [[1,2,3],[2,3,1],[3,1,2]]return = trueEach row and each column contains 1, 2, and 3 exactly once.
Example 2
matrix = [[1,2],[1,2]]return = falseBoth rows contain the required values, but each column repeats a value.
Example 3
matrix = [[2]]return = falseA Latin square of size 1 must contain 1.
Constraints
1 <= n == matrix.length <= 200.- Every row has exactly
nelements. -10^9 <= matrix[i][j] <= 10^9.