Function to find if the grid can be made alternating
function findPossibleGrid ( n , m , a ) { let flag = true ; let k = - 1 , o = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] != " " ) {