Problem 238647 · easy · Phase 02 Linear Data Structures

Symmetric Grid Check

2d-lists · symmetry · boolean-logic

A square grid is symmetric when the value at row r, column c equals the value at row c, column r for every pair of indices. Given a grid grid, return True if it is square and symmetric, otherwise False. An empty grid counts as symmetric.

Examples

Input:  grid = [[1, 2, 3],
                [2, 5, 6],
                [3, 6, 9]]
Output: True

Input:  grid = [[1, 2],
                [3, 1]]
Output: False

Input:  grid = [[1, 2, 3]]
Output: False
Explanation: a 1x3 grid is not square.

Constraints

  • 0 <= rows, cols <= 100

Goals

  • Compare a cell with its mirror across the main diagonal
  • Reject non-square grids before comparing cells
Starting Python…