Given a 0-indexed n x n integer matrix grid, return the number of pairs (Ri, Cj) such that row Ri and column Cj are equal.

A row and column pair is considered equal if they contain the same elements in the same order (i.e. an equal array).

&nbsp;
Example 1:

Input: grid = [[3,2,1],[1,7,6],[2,7,7]]
Output: 1
Explanation: There is 1 equal row and column pair:
- (Row 2, Column 1): [2,7,7]


Example 2:

Input: grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]
Output: 3
Explanation: There are 3 equal row and column pairs:
- (Row 0, Column 0): [3,1,2,2]
- (Row 2, Column 2): [2,4,2,2]
- (Row 3, Column 2): [2,4,2,2]


&nbsp;
Constraints:


	n == grid.length == grid[i].length
	1 &lt;= n &lt;= 200
	1 &lt;= grid[i][j] &lt;= 105


class Solution:
    def equalPairs(self, grid: List[List[int]]) -> int:
        m = defaultdict(int)
        cnt = 0

        for row in grid:
            m[str(row)] += 1
        
        for i in range(len(grid[0])):
            col = []
            for j in range(len(grid)):
                col.append(grid[j][i])
            cnt += m[str(col)]
        return cnt
class Solution {
    public int equalPairs(int[][] grid) {
        HashMap<String, Integer> map = new HashMap<>();
        int row = grid.length;
        int col = grid.length;
        for(int i = 0; i < row; i++){
            String res = "";
            for(int j = 0; j < col; j++){
                res += "-" + grid[i][j];
            }
            map.put(res, map.getOrDefault(res, 0) + 1);
        }
        int cnt = 0;
        for(int j = 0; j < col; j++){
            String res = "";
            for(int i = 0; i < row; i++){
                res += "-" + grid[i][j];
            }
            cnt += map.getOrDefault(res, 0);
        }
        return cnt;
    }
}
class Solution {
public:
    int equalPairs(vector<vector<int>>& grid) 
    {
        // Number to store the count of equal pairs.
        int ans = 0;
        map<vector<int>, int> mp;
        // Storing each row int he map
        for (int i = 0; i < grid.size(); i++)
            mp[grid[i]]++;
        
        for (int i = 0; i < grid[0].size(); i++)
        {
            vector<int> v;
            // extracting column in a vector.
            for (int j = 0; j < grid.size(); j++)
                v.push_back(grid[j][i]);
            // Add the number of times that column appeared as a row.
            ans += mp[v];
        }
        // Return the number of count
        return ans;
    }
};
var equalPairs = function(grid) {
    let n = grid.length
    let count = 0;

    let map = new Map()

    //making rowArray
    for(let row = 0; row < n; row++){
        let temp = []
        for(let col = 0; col < n; col++){
            temp.push(grid[row][col])
        }

        temp = temp.join()

        if(map.has(temp)){
            let tempCount = map.get(temp)
            map.set(temp, tempCount+1)
        }
        else{
            map.set(temp, 1)
        }
    }

    for(let col = 0; col < n; col++){
        let temp = []
        for(let row = 0; row < n; row++){
            temp.push(grid[row][col])
        }

        temp = temp.join()

        if(map.has(temp)){
            count += map.get(temp)
        }
    }

    return count;
};
Equal Row and Column Pairs