FunctionRacerProblemsRace

Is It the Transpose

EasyGridsPython, JavaScript, TypeScript, Java, C++

Return True if b is the transpose of a, and False otherwise. b is the transpose of a when b has as many rows as a has columns, as many columns as a has rows, and b[j][i] == a[i][j] for every row i and column j of a. Both grids are rectangular: within one grid all rows have the same length.

Example 1

a [[1,2,3],[4,5,6]]
b [[1,4],[2,5],[3,6]]
returns true

The rows of a are the columns of b.

Example 2

a [[1,2],[3,4]]
b [[1,2],[3,4]]
returns false

b[0][1] is 2 but a[1][0] is 3, so b is only a copy of a, not its transpose.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems