Skip to content
Decoder

Equal Row and Column Pairs

Medium

Problem

Given an n x n integer grid, return the number of pairs (r, c) such that row `r` and column `c` are equal: they contain the same values in the same order (column read from top to bottom).

Example 1

grid = [[3, 2, 1],

Example 2

        [1, 7, 6],

Example 3

Input
[2, 7, 7]]
Output
1
Why
row 2 equals column 1: [2, 7, 7]

Example 4

grid = [[1, 1],

Example 5

Input
[1, 1]]
Output
4
Why
every row equals every column

Constraints

  • n == grid.length == grid[i].length
  • 1 <= n <= 200
  • 1 <= grid[i][j] <= 10^5

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.