An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).

Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.

&nbsp;
Example 1:

Input: matrix = [[1,2,3],[3,1,2],[2,3,1]]
Output: true
Explanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3.
Hence, we return true.


Example 2:

Input: matrix = [[1,1,1],[1,2,3],[1,2,3]]
Output: false
Explanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3.
Hence, we return false.


&nbsp;
Constraints:


	n == matrix.length == matrix[i].length
	1 &lt;= n &lt;= 100
	1 &lt;= matrix[i][j] &lt;= n


class Solution:
    def checkValid(self, matrix: List[List[int]]) -> bool:
        lst = [0]*len(matrix)
        for i in matrix:
            if len(set(i)) != len(matrix):
                return False
            for j in range(len(i)):
                lst[j] += i[j]
        return len(set(lst)) == 1
class Solution {
    public boolean checkValid(int[][] matrix) {
        int n = matrix.length;
        int num = (n*(n+1))/2; // SUM of n number 1 to n;

        for(int i=0; i<n; i++)
        {
            HashSet<Integer> hs = new HashSet<Integer>();
              HashSet<Integer> hs1 = new HashSet<Integer>();

            int m = num; int k = num;

            for(int j = 0; j<n; j++)
            {
                hs.add(matrix[i][j]);
                  hs1.add(matrix[j][i]);
                m -= matrix[i][j];
                k -= matrix[j][i];
            }

            if(m != 0 || k != 0 || hs.size() != n || hs.size() != n)
            {
                return false;
            }
        }
        return true;
    }
}
class Solution {
public:
    bool checkValid(vector<vector<int>>& matrix) {
        int n=matrix.size();
        unordered_set<int> s1, s2;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(s1.find(matrix[i][j])!=s1.end())
                    return false;
                else
                    s1.insert(matrix[i][j]);
                if(s2.find(matrix[j][i])!=s2.end())
                    return false;
                else
                    s2.insert(matrix[j][i]);
            }
            s1.clear();
            s2.clear();
        }
        return true;
    }
};
var checkValid = function(matrix) {    
    for(let i =0; i<matrix.length;i++){
        const cols = new Set(), rows = new Set(matrix[i]);
		
        for(let j =0; j<matrix.length;j++){
            if(matrix[j][i] > matrix.length) return false;
            cols.add(matrix[j][i])
        }
		
        if(cols.size < matrix.length || rows.size < matrix.length) return false;
    }
    return true;
};
Check if Every Row and Column Contains All Numbers