Ctrl K

Cross-Stitch Pattern

Easy
An embroiderer stores a design as a square table pattern of size n × n: each cell holds a thread number, and 0 means the cell is empty. The design is a **cross** when: - neither diagonal (top-left to bottom-right, and top-right to bottom-left) has an empty cell; - every cell off the diagonals is empty. Return True if pattern is a cross, and False otherwise.
Example 1
pattern=[[4, 0, 7], [0, 9, 0], [1, 0, 3]] → True

Both diagonals are filled (4, 9, 3 and 7, 9, 1) and every other cell is zero, so it is a cross.

Example 2
pattern=[[2, 0, 0, 5], [0, 1, 6, 0], [0, 8, 0, 0], [3, 0, 0, 4]] → False

The cell on the main diagonal in the third row is 0, so a stitch is missing.

Example 3
pattern=[[1, 0, 1], [0, 1, 0], [1, 2, 1]] → False

The diagonals are filled, but there is a stray stitch (2) in the middle of the bottom row.

Constraints
  • 3 ≤ n ≤ 100
  • pattern is a square n × n table
  • 0 ≤ pattern[i][j] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
pattern=[[4, 0, 7], [0, 9, 0], [1, 0, 3]]
Expected
True

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