Rows That Match Columns
grid is a square grid of integers with n rows and n columns. Count the pairs (r, c) such that row r, read from left to right, is exactly the same sequence as column c, read from top to bottom.
Return the number of such pairs. Every row is compared with every column, so r == c is allowed, and a row that equals several columns counts once per column.
Example 1
grid [[3,2,1],[1,7,6],[2,7,7]]
returns 1
Row 2 is 2, 7, 7 and column 1 is 2, 7, 7; no other row equals a column.
Example 2
grid [[1,2],[2,1]]
returns 2
Row 0 equals column 0 and row 1 equals column 1.
Constraints
1 <= n <= 10, andgridhasnrows ofnvalues-10 <= grid[i][j] <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.