Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.23 KB

File metadata and controls

37 lines (27 loc) · 1.23 KB
Problem:

A typical American-style crossword puzzle grid is an N x N matrix with black and white squares, which obeys the following rules:

* Every white square must be part of an "across" word and a "down" word.
* No word can be fewer than three letters long.
* Every white square must be reachable from every other white square.

The grid is rotationally symmetric (for example, the colors of the top left and bottom right squares must match). Write a program to determine whether a given matrix qualifies as a crossword grid.

Steps for checking validity of white sqaure

  1. Generate a set (hash-list) of white square positions
  2. Select a white square and run BFS/DFS for all adjoining white square and remove the visited square positions from the white square position set.
  3. If the set is non-empty after visiting all the adjoining white squares, the crossword is invalid.

Pseudo-code for checking validity of rotationally symmetricity for grid

# NOTE: this is a PSEUDO-CODE
n = number of rows
m = number of columns

for i in range(0, n / 2):
    for j in range(0, m / 2):
        if grid[i][j] != grid[n - 1 - i][m - 1 - j]:
            return False
return True

NOTE

The question is vague without example