Problem
You get an n x n integer matrix grid. Return the number of pairs (r, c) where row r and column c are equal.
A row and a column are equal when they have the same items in the same order. Read a row from left to right, and read a column from top to bottom.
Example 1
- Input:
- grid = [[5,1,5],[1,2,1],[5,1,5]]
- Output:
- 5
- Explanation:
- Rows 0 and 2 are equal to columns 0 and 2, which gives 4 pairs. Row 1 is equal to column 1, which gives 1 more pair.
Example 2
- Input:
- grid = [[1,2],[3,4]]
- Output:
- 0
- Explanation:
- The columns are
[1, 3]and[2, 4]. No row is equal to a column.
Example 3
- Input:
- grid = [[6,9,6],[9,1,1],[6,8,6]]
- Output:
- 1
- Explanation:
- Row 0 and column 0 are both
[6, 9, 6].
Constraints
- n == grid.length == grid[i].length
- 1 <= n <= 200
- 1 <= grid[i][j] <= 10^5
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 2352. Equal Row and Column Pairs
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source