Equal Row and Column Pairs LeetCode solution in C++
1class Solution {2public:3int equalPairs(vector<vector<int>> &grid) {4// Number to store the count of equal pairs.5int ans = 0;6map<vector<int>, int> mp;7// Storing each row int he map8for (int i = 0; i < grid.size(); i++) mp[grid[i]]++;910for (int i = 0; i < grid[0].size(); i++) {11vector<int> v;12// extracting column in a vector.13for (int j = 0; j < grid.size(); j++) v.push_back(grid[j][i]);14// Add the number of times that column appeared as a row.15ans += mp[v];16}17// Return the number of count18return ans;19}20};