Ctrl K

Crossword That Reads Both Ways

Easy
A puzzle setter filled a grid row by row: rows[i] is row i, its letters are flush with the left edge, and rows may differ in length. Column k reads from top to bottom and is made of the k-th letters of the rows, for as long as they have one. The grid works if, for every k, row k and column k both exist and read the same. Return True if the grid works, and False otherwise.
Example 1
rows=["cat", "ape", "ten"] → True

Row 0 and column 0 both read cat, row 1 and column 1 read ape, row 2 and column 2 read ten.

Example 2
rows=["sea", "ex", "a"] → True

The rows have different lengths, but the columns read sea, ex, a, which matches.

Example 3
rows=["map", "ago", "pen"] → False

Row 2 reads pen, while column 2 reads pon.

Constraints
  • 1 ≤ len(rows) ≤ 500
  • 1 ≤ len(rows[i]) ≤ 500
  • rows[i] consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool EasyConstant Diagonals Easy
loading Python…
Input
rows=["cat", "ape", "ten"]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.