Today I have solved the problem in javascript

 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 gridconst

 crosswordMatrix = [

    ['W', 'W', 'B', 'W', 'W'],

    ['W', 'W', 'W', 'B', 'W'],

    ['B', 'W', 'B', 'W', 'B'],

    ['W', 'B', 'W', 'W', 'W'],

    ['W', 'W', 'B', 'W', 'W']

];


function isCrosswordGrid(matrix) {

    const n = matrix.length;

    for (let i = 0; i < n / 2; i++) {

        for (let j = 0; j < n; j++) {

            if (matrix[i][j] !== matrix[n - 1 - i][n - 1 - j]) {

                return false;

            }

        }

    }

for (let i = 0; i < n; i++) {

        for (let j = 0; j < n; j++) {

            if (matrix[i][j] === 'W') {

               

                if ((j === 0 || matrix[i][j - 1] === 'B') && (j < n - 2 && matrix[i][j + 1] === 'W' && matrix[i][j + 2] === 'W')) {

                    

                    if ((i === 0 || matrix[i - 1][j] === 'B') && (i < n - 2 && matrix[i + 1][j] === 'W' && matrix[i + 2][j] === 'W')) {

                        continue;

                    } else {

                        return false;

                    }

                } else {

                    return false;

                }

            }

        }

    }


    return true;

}

console.log(isCrosswordGrid(crosswordMatrix));  

Output:

false

Comments

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript